# Database querying

In some cases it can be useful to query the UXWizz database directly. This page explains the database structure and how the data is stored in it.

## Database structure

{% hint style="warning" %}
**NOTE:** This was the database structure for version 8.5.0.\
A newerer version might include new tables.
{% endhint %}

Here is a diagram created using `PHPMyAdmin->Designer` for an existing UXWizz database:

<figure><img src="https://2006615411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ltuu0c63_YY4iXfi5vJ%2Fuploads%2FyiyVEGGyNQGtSssCejwr%2FScreenshot%202025-07-22%20133607.png?alt=media&#x26;token=f5ff9a4d-23f7-4d9d-a11a-20e2ec662b53" alt="UXWizz database structure"><figcaption></figcaption></figure>

### Remarks

* **ust\_clients** - Stores unique **sessions/visits**. An unique user can have multiple entries. The `ip` can be used to link all sessions from the user.
* **ust\_clientpage** - Stores unique **pageviews**. Each session has multiple pageviews.
* **ust\_records/ust\_partials** - Store the record playback information for a specific **pageview**.
* **ust\_movements/ust\_clicks** - Heatmap data, stored per **pageview**.
* **ust\_client\_tag** - Session level **tag/label/event data**.
* **ust\_client\_event** - **Events** stored linked to a specific pageview, session and user.
* **ust\_ab** - Stores AB tests
* **ust\_users** (internal) - Stores list of UXWizz dashboard users
* **ust\_access** (internal) - Stores which domain data can be accessed by which users

{% hint style="info" %}
For improved performance, there are multiple indexes already created. Those indexes are specifically created for the queries ran for the UXWizz dashboard, but they should also lead to very fast query performance in most cases.
{% endhint %}

### Examples

{% hint style="info" %}
You can **find many example queries in the PHP source code of UXWizz**. \
Usually each PHP file only runs a single query.
{% endhint %}

#### Basic query

```sql
SELECT * FROM `ust_clients` WHERE `domain`="domain.com" 
```

#### Domain change (move all users tracked from one domain to another)

```sql
UPDATE ust_clients SET `domain`='new.com' WHERE `domain`='old.com';
```

#### Get the path each visitor took before first reaching the pricing page:

```sql
SELECT 
    t1.clientid as clientID, 
    GROUP_CONCAT(t1.page ORDER BY t1.id ASC SEPARATOR ' -> ') as path 
FROM 
    ust_clientpage t1 
WHERE 
    t1.id <= ( 
        SELECT MIN(t2.id) as min_id FROM ust_clientpage t2 
        WHERE t2.page LIKE '%pricing%' AND t2.clientid = t1.clientid 
    ) 
    AND t1.clientid IN (SELECT id FROM ust_clients WHERE domain = 'uxwizz.com')
GROUP BY t1.clientid 
ORDER BY t1.clientid 
DESC LIMIT 10;

# Example output:
# [{"clientID":126951,"path":"/hotjar-alternative -> /pricing"}]
```
