Cross-database queries in the SQL editor
The SQL editor is connected to one database. On Hostinger each database
also has its own MySQL user, so MySQL itself refuses a query like
SELECT … FROM other_db.some_table.
Cross-database queries get around this. When a SELECT names a table in
another engine database, the editor does not send it to MySQL. The Query
Executor runs it instead:
- Each table is read on its own database connection.
- The rows are joined by the engine (MultiTable).
- The engine applies your
WHERE,GROUP BY,ORDER BYandLIMIT.
You write normal SQL. The result looks like any other result in the editor, with these labels:
- the result tab is called Engine join, not Result;
- the status line starts with Engine join · 4 rows · 12 ms;
- the Messages tab shows an engine join badge. Hover over it to see which database and table each alias came from.
This guide lists everything you can write, with an example of each.
In all examples,
u123456789stands for your hosting account prefix. Your real database names look likeu123456789_sp_datamanagerandu123456789_sp_db_auth.
Contents
- Quick start
- When a query takes this route
- Naming databases and tables
- SELECT: choosing columns
- JOIN
- WHERE: every condition you can write
- Values: strings, numbers, NULL, TRUE/FALSE
- Parameters (? and :name)
- Aggregates: COUNT, SUM, AVG, MIN, MAX
- GROUP BY
- DISTINCT
- ORDER BY
- LIMIT and OFFSET
- Comments, quoting, semicolons
- EXPLAIN
- Hidden (credential) columns
- Limits and how results can differ from MySQL
- What is not supported (and what to write instead)
- Error messages
- Recipes
- Settings (.env)
- Cheat sheet
1. Quick start
Connect the editor to the data manager database, type this, and press Run (not Run script):
SELECT t.sp_user_uid, t.sp_start_time, t.sp_duration, u.sp_user_email
FROM u123456789_sp_datamanager.tsp_time_manager AS t
LEFT JOIN u123456789_sp_db_auth.tsp_sys_users AS u
ON t.sp_user_uid = u.sp_user_uid
Every time log comes back with its user's email. A log whose user does not
exist shows NULL in sp_user_email, which is what LEFT JOIN means.
The same query in its short form:
- the editor's own database needs no prefix;
- the other database can be named by its handle (see §3).
SELECT t.sp_user_uid, t.sp_start_time, t.sp_duration, u.sp_user_email
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
2. When a query takes this route
A statement goes to the Query Executor only when all of these are true:
| Condition | If not |
|---|---|
It starts with SELECT | Normal path. UPDATE other_db.x … is still refused, so writes never cross databases. |
| It names at least one engine database other than the editor's own | Normal path. Plain single-database SQL runs exactly as before. |
| You pressed Run or Explain, and only one statement is sent | Run script uses the normal path, which reports the CROSS_SCHEMA error. Select one statement and press Run. |
| You are on MySQL in the editor (not a SQLite store) | Normal path. |
SQL_EDITOR_CROSS_DB is not false | Normal path (CROSS_SCHEMA error). |
Engine databases are the ones listed in SepoEngine/Apps/AppsConfig.php
(auth, UI registry, data manager, apps). information_schema, mysql and
any database not in that list never take this route.
Tip: if you select part of the text in the editor, only the selection is sent, so you can run one query out of a page of SQL.
3. Naming databases and tables
3.1 Three ways to name the database
-- 1. Physical name (as on the server)
SELECT u.sp_user_email FROM u123456789_sp_db_auth.tsp_sys_users u
-- 2. Logical handle (as in AppsConfig.php): shorter, and the same locally and on Hostinger
SELECT u.sp_user_email FROM sp_db_auth.tsp_sys_users u
-- 3. No database at all = the database the editor is connected to
SELECT t.sp_date FROM tsp_time_manager t JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
Database names are matched case-insensitively, so
U123456789_SP_DB_AUTH also works.
A query that only names the editor's own database (
SELECT … FROM u123456789_sp_datamanager.tsp_time_managerwhile connected to it) is a normal query and runs on the normal path.
3.2 Aliases
FROM sp_db_auth.tsp_sys_users AS u -- with AS
FROM sp_db_auth.tsp_sys_users u -- without AS
FROM sp_db_auth.tsp_sys_users -- no alias: the alias is the table name
Without an alias, refer to the columns with the table name:
SELECT tsp_sys_users.sp_user_email FROM sp_db_auth.tsp_sys_users
Alias rules:
- letters, digits and
_only, not starting with a digit; - no double underscore (
u__xis refused, because the engine uses__internally); - each alias once per query (
uandUcount as the same).
Aliases are matched case-insensitively (U.sp_user_email finds alias u).
3.3 Table names
A table name may contain letters, digits, _ and $. Backticks are fine
(see §14).
3.4 A single table from another database
You do not need a join. Reading one table from another database is supported:
SELECT sp_user_uid, sp_user_email, sp_user_group
FROM sp_db_auth.tsp_sys_users
WHERE sp_user_group = 'LibraryDepartment'
ORDER BY sp_user_email
SELECT COUNT(*) FROM sp_db_auth.tsp_sys_users
4. SELECT: choosing columns
4.1 Columns with an alias
SELECT t.sp_date, t.sp_start_time, u.sp_user_firstname, u.sp_user_email
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
4.2 Columns without an alias
This works when the column exists in exactly one table of the query:
SELECT sp_start_time, sp_user_email -- each is in only one table
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
If both tables have the column, you must say which one:
SELECT sp_user_uid FROM … -- ✗ "Column 'sp_user_uid' is in more than one table (t, u); qualify it with the alias."
SELECT t.sp_user_uid FROM … -- ✓
Column names are matched case-insensitively. The result shows the real name as stored in the table.
4.3 Renaming result columns (AS)
SELECT t.sp_date AS day,
u.sp_user_email AS "Email address", -- quotes allow spaces
u.sp_user_firstname name -- AS is optional
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
You can quote a name with '…', "…" or backticks.
4.4 Same column name from two tables
Both columns are kept, side by side, exactly as MySQL would show them:
SELECT t.sp_user_uid, u.sp_user_uid
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
-- result columns: sp_user_uid | sp_user_uid
-- the second one is NULL when the user does not exist
Use AS to tell them apart: t.sp_user_uid AS log_user, u.sp_user_uid AS found_user.
4.5 All columns of one table: alias.*
SELECT t.sp_date, u.*
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
Credential columns (passwords, secrets, tokens…) are left out of u.*
automatically. A note in Messages lists them. See §16.
4.6 Everything: *
SELECT *
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
* returns all columns of t, then all of u, without credential columns.
4.7 SELECT ALL
SELECT ALL … is accepted and means the same as SELECT ….
4.8 What you can NOT put in the select list
Only plain columns, alias.*, * and the five aggregates are allowed:
SELECT UPPER(u.sp_user_email) … -- ✗ functions
SELECT t.sp_duration / 60 … -- ✗ arithmetic
SELECT CONCAT(u.sp_user_firstname, ' ') … -- ✗
SELECT CASE WHEN … END … -- ✗
SELECT 'fixed text' … -- ✗ literals
Instead, run the query, then use Export or Open in spreadsheet to
calculate. For a saved, reusable calculation, use a Query Executor query
with math_config.calculations.
5. JOIN
5.1 LEFT JOIN: keep every row of the left table
SELECT t.sp_time_log_id, u.sp_user_email
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
LEFT OUTER JOIN is the same thing.
5.2 INNER JOIN: keep only rows that have a match
SELECT t.sp_time_log_id, u.sp_user_email
FROM tsp_time_manager t
INNER JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
A bare JOIN means INNER JOIN:
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
5.3 The ON clause
These are the rules:
- one equality between two columns:
ON b.col = a.col; - both sides qualified with their alias;
- one side is the table being joined, the other a table that appears earlier in the query;
- the two sides can be written in either order.
ON u.sp_user_uid = t.sp_user_uid -- ✓
ON t.sp_user_uid = u.sp_user_uid -- ✓ same thing
ON sp_user_uid = sp_user_uid -- ✗ qualify both sides
ON u.sp_user_uid = t.sp_user_uid AND u.sp_user_work_active = 1 -- ✗ one condition only
To add an extra condition, move it to WHERE:
SELECT t.sp_time_log_id, u.sp_user_email
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE u.sp_user_work_active = 1
LEFT JOIN with an extra condition. In MySQL,
LEFT JOIN u ON … AND u.x = 1keeps everytrow and blanksuwherexis not 1. Movingu.x = 1toWHEREdrops those rows instead. To keep them, writeWHERE (u.x = 1 OR u.sp_user_uid IS NULL). That gives the same rows, except rows whoseumatch exists but fails the test.
5.4 Three or more tables (chains)
Each JOIN may connect to any table before it, not only the first one:
SELECT t.sp_time_log_id, u.sp_user_email, s.can_select_data
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
LEFT JOIN sp_db_auth.tsp_sys_security s ON s.sp_user_uid = u.sp_user_uid
LEFT and INNER can be mixed:
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
INNER JOIN sp_db_auth.tsp_sys_security s ON s.sp_user_uid = u.sp_user_uid
Tables from the same other database can be joined to each other too. Every table is read on its own database's connection.
5.5 How joins are done (why it matters for speed)
- The first table (after
FROM) is read, with theWHEREconditions that only use its own columns. - For each joined table, only the rows whose key matches a key already
loaded are read, as
WHERE key IN (…), 500 keys per query. - The rows are merged in PHP, then the rest of
WHEREis applied.
So:
- Put the most selective table first and filter it in
WHERE; that filter goes straight into its SQL. - Index the join columns (
sp_user_uidand similar).
5.6 Joins that are not supported
| Write | Instead |
|---|---|
RIGHT JOIN b … | Swap the tables and use LEFT JOIN: FROM b LEFT JOIN a ON … |
FULL JOIN | Not available |
CROSS JOIN, FROM a, b | Use JOIN … ON |
NATURAL JOIN | JOIN … ON b.col = a.col |
JOIN … USING (col) | JOIN … ON b.col = a.col |
ON with two conditions | One in ON, the rest in WHERE (see the note in §5.3) |
ON a.x > b.y | Equality only |
6. WHERE: every condition you can write
A condition always compares a column with a value (or a parameter). You
cannot compare two columns in WHERE; that is what JOIN … ON is for.
All the examples below use this join:
SELECT t.sp_time_log_id, t.sp_date, u.sp_user_email
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE …
6.1 Equal: =
WHERE u.sp_user_group = 'LibraryDepartment'
WHERE t.sp_log_active = 1
WHERE t.sp_date = '2026-10-14'
Text equality is case-insensitive, as in MySQL:
= 'librarydepartment' matches LibraryDepartment. The exception is a value
that contains %, _ or \: that comparison is exact.
6.2 Not equal: != or <>
WHERE u.sp_user_group != 'Finance'
WHERE u.sp_user_group <> 'Finance' -- same
As in SQL, a row where the column is NULL does not match !=. Add
OR … IS NULL if you want those rows too:
WHERE (u.sp_user_group != 'Finance' OR u.sp_user_group IS NULL)
6.3 Greater / less: >, <, >=, <=
WHERE t.sp_duration > 60
WHERE t.sp_duration <= 480
WHERE t.sp_date >= '2026-10-01' -- dates as 'YYYY-MM-DD' compare correctly
WHERE t.sp_start_time < '2026-10-14 12:00:00'
A NULL never matches <, >, <= or >=, as in SQL.
6.4 Value first
The value can come first; the comparison is turned around for you:
WHERE 60 < t.sp_duration -- same as t.sp_duration > 60
WHERE '2026-10-01' <= t.sp_date -- same as t.sp_date >= '2026-10-01'
6.5 Ranges: BETWEEN … AND … and NOT BETWEEN
Both ends are included:
WHERE t.sp_date BETWEEN '2026-10-01' AND '2026-10-31'
WHERE t.sp_duration NOT BETWEEN 30 AND 480
For a whole day using a date-time column, write
t.sp_start_time BETWEEN '2026-10-14 00:00:00' AND '2026-10-14 23:59:59'ort.sp_start_time >= '2026-10-14' AND t.sp_start_time < '2026-10-15'.
6.6 Lists: IN (…) and NOT IN (…)
WHERE u.sp_user_uid IN ('u1', 'u7', 'u12')
WHERE t.sp_time_log_id IN (101, 102, 103)
WHERE u.sp_user_group NOT IN ('Finance', 'Archive')
- At least one value; values can be strings, numbers or parameters.
NULLis not allowed inside the list. UseIS NULL(§6.8).NOT INdoes not match rows where the column is NULL, as in SQL.IN (SELECT …)subqueries are not supported (see §20.4 for a workaround).
6.7 Patterns: LIKE and NOT LIKE
% means any number of characters and _ means exactly one. Matching is
case-insensitive.
WHERE u.sp_user_email LIKE '%@sepodesk.com' -- ends with
WHERE u.sp_user_firstname LIKE 'jo%' -- starts with (also matches "John", "JOANNA")
WHERE u.sp_user_email LIKE '%admin%' -- contains
WHERE t.sp_date LIKE '2026-10-%' -- every day in October 2026
WHERE u.sp_user_uid LIKE 'u_' -- "u" + exactly one character
WHERE u.sp_user_email NOT LIKE '%@test.%'
Not available: ESCAPE, REGEXP / RLIKE, SOUNDS LIKE.
6.8 Empty values: IS NULL and IS NOT NULL
WHERE u.sp_user_uid IS NULL -- logs whose user does not exist (LEFT JOIN)
WHERE u.sp_user_category IS NOT NULL
= NULL is refused, because it is never true in SQL; the message tells you
to use IS NULL.
6.9 Combining: AND, OR, NOT, brackets
WHERE u.sp_user_group = 'LibraryDepartment' AND t.sp_log_active = 1
WHERE u.sp_user_group = 'Finance' OR t.sp_duration > 480
WHERE (u.sp_user_group = 'Finance' OR u.sp_user_group = 'HR')
AND t.sp_date >= '2026-10-01'
WHERE NOT (u.sp_user_group = 'Finance' OR t.sp_log_active = 0)
WHERE NOT u.sp_user_email LIKE '%@test.%'
Precedence is the usual one: NOT binds tightest, then AND, then OR.
Use brackets whenever you mix AND and OR.
MySQL's symbol forms work as well:
| Word | Symbol | ||
|---|---|---|---|
AND | && | ||
OR | `\ | \ | ` |
NOT | ! |
WHERE t.sp_log_active = 1 && !(u.sp_user_group = 'Finance')
Not available: XOR.
6.10 Conditions on either table, anywhere
Any condition can use any table in the query:
WHERE u.sp_user_work_active = 1 -- joined table
AND t.sp_date = '2026-10-14' -- first table
Conditions that use only the first table are sent to its database (fast). Conditions on joined tables are checked after the join (see §17.1).
7. Values: strings, numbers, NULL, TRUE/FALSE
| Kind | Examples | Notes |
|---|---|---|
| Text | 'LibraryDepartment', "double quotes work too" | Write a quote inside the text by doubling it ('O''Brien') or with a backslash ('O\'Brien'). \n, \t and \\ work as in MySQL. |
| Whole number | 42, -7, +3 | |
| Decimal | 1.5, -0.25, .5, 1e3 | |
| Date / time | '2026-10-14', '2026-10-14 08:30:00' | Written as text; compare correctly when in this format. |
| Boolean | TRUE, FALSE | Same as 1 and 0. |
| NULL | NULL | Only in IS NULL / IS NOT NULL. |
| Parameter | ?, :name | See §8. |
Numbers stored as text ('42') and real numbers (42) compare as numbers,
as in MySQL.
8. Parameters (? and :name)
Use parameters exactly as in normal editor queries. When you press Run, the editor asks for the values; they are never pasted into the SQL.
8.1 Positional ?
SELECT t.sp_time_log_id, u.sp_user_email
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE u.sp_user_group = ?
AND t.sp_date BETWEEN ? AND ?
Values are used in order: first ? = group, second = from-date, third = to-date.
8.2 Named :name
SELECT t.sp_time_log_id, u.sp_user_email
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE u.sp_user_uid = :who
OR t.sp_user_uid = :who -- the same name can be used twice
8.3 Where parameters can go
- In any
WHEREvalue, including insideIN (…)andBETWEEN. - In
LIMITandOFFSET:
… ORDER BY t.sp_date DESC LIMIT :rows OFFSET :skip
If a parameter has no value, you get Parameter :who has no value.
9. Aggregates: COUNT, SUM, AVG, MIN, MAX
9.1 What each one does
| Write | Result | NULLs |
|---|---|---|
COUNT(*) | number of rows | counted |
COUNT(a.col) | rows where col is not NULL | skipped |
COUNT(DISTINCT a.col) | number of different non-NULL values | skipped |
SUM(a.col) | total | skipped; NULL if there are no values |
SUM(DISTINCT a.col) | total of the different values | skipped |
AVG(a.col) | average, rounded to 4 decimals | skipped; NULL if there are no values |
AVG(DISTINCT a.col) | average of the different values | skipped |
MIN(a.col) / MAX(a.col) | smallest / largest. Numbers compare as numbers, text case-insensitively, dates as text (fine for YYYY-MM-DD). | skipped |
* is only valid in COUNT(*); SUM(*) is refused.
9.2 Over the whole result (no GROUP BY)
One row comes back, even when nothing matches (then COUNT = 0 and the
others are NULL):
SELECT COUNT(*) AS logs,
COUNT(DISTINCT t.sp_user_uid) AS people,
SUM(t.sp_duration) AS minutes,
AVG(t.sp_duration) AS avg_minutes,
MIN(t.sp_start_time) AS first_in,
MAX(t.sp_start_time) AS last_in
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date = '2026-10-14'
9.3 Column names of aggregates
Without AS, the column is named after what you wrote, as in MySQL:
COUNT(*), SUM(t.sp_duration), COUNT(DISTINCT t.sp_user_uid). Use AS to
choose a shorter name that you can also sort by (§12).
9.4 Mixing aggregates and plain columns
When the select list has an aggregate, every plain column must also be in
GROUP BY:
SELECT u.sp_user_group, COUNT(*) FROM … GROUP BY u.sp_user_group -- ✓
SELECT u.sp_user_group, COUNT(*) FROM … -- ✗ "…is selected but is neither in GROUP BY nor inside an aggregate."
10. GROUP BY
10.1 One column
SELECT u.sp_user_group, COUNT(*) AS logs, SUM(t.sp_duration) AS minutes
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
GROUP BY u.sp_user_group
Rows where u.sp_user_group is NULL (for example, logs without a user) form
their own group, shown with a NULL group value, as in MySQL.
10.2 Several columns
SELECT t.sp_date, u.sp_user_group, COUNT(*) AS logs
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
GROUP BY t.sp_date, u.sp_user_group
ORDER BY t.sp_date, u.sp_user_group
10.3 Three ways to name a group column
GROUP BY u.sp_user_group -- the column
GROUP BY grp -- a name given with AS: SELECT u.sp_user_group AS grp
GROUP BY 1 -- its position in the select list (1 = first)
10.4 Grouping by a column you do not show
This is allowed; the group column is used even though it is not displayed:
SELECT COUNT(*) AS logs, SUM(t.sp_duration) AS minutes
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
GROUP BY u.sp_user_group
10.5 Not supported
HAVING: sort by the aggregate instead (§12.4), or filter the result in the grid.WITH ROLLUP: run a second query withoutGROUP BYfor the totals.- Grouping by an expression (
GROUP BY LEFT(t.sp_date, 7)). For per-month totals, see §20.5.
11. DISTINCT
Removes duplicate rows from the result:
SELECT DISTINCT u.sp_user_group
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
SELECT DISTINCT t.sp_user_uid, u.sp_user_firstname
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
ORDER BY u.sp_user_firstname
Duplicates are judged on the columns you selected. Two NULLs count as equal.
12. ORDER BY
12.1 By a column, ascending or descending
ORDER BY t.sp_start_time -- ascending (ASC is the default)
ORDER BY t.sp_start_time ASC
ORDER BY t.sp_start_time DESC
12.2 Several columns
ORDER BY u.sp_user_group, t.sp_start_time DESC
12.3 By a result name, a quoted name or a position
SELECT t.sp_date AS day, u.sp_user_email AS email FROM … ORDER BY day DESC
SELECT u.sp_user_email AS "Email address" FROM … ORDER BY 'Email address'
SELECT t.sp_date, u.sp_user_email FROM … ORDER BY 2, 1 DESC
12.4 By an aggregate (grouped queries)
The aggregate must also be in the select list:
SELECT u.sp_user_group, COUNT(*) AS logs
FROM …
GROUP BY u.sp_user_group
ORDER BY logs DESC -- by its name
-- or: ORDER BY COUNT(*) DESC -- by writing it the same way
-- or: ORDER BY 2 DESC -- by position
In a grouped query you can sort by a GROUP BY column or a selected
aggregate. Any other column is refused, because it has no single value per
group.
12.5 Sorting by a column you do not show
This is fine in queries without GROUP BY:
SELECT u.sp_user_email FROM … ORDER BY t.sp_start_time DESC
12.6 How values sort
- NULL first in ascending order, last in descending order (as in MySQL).
NULLS FIRST/NULLS LASTare not supported. - Numbers as numbers:
9before10, even when stored as text. - Text case-insensitively:
anna,Bob,carl. - Dates and times as text, which is correct for
YYYY-MM-DD hh:mm:ss. - Rows with equal values keep the order in which they were read.
13. LIMIT and OFFSET
LIMIT 50 -- first 50 rows
LIMIT 50 OFFSET 100 -- rows 101-150
LIMIT 100, 50 -- the same thing, MySQL's short form (offset, count)
LIMIT ? OFFSET ? -- with parameters
- Whole numbers of 0 or more only.
- Use
ORDER BYwithOFFSETfor pages that stay stable from run to run. - The editor's row cap (
SQL_EDITOR_MAX_ROWS, or the max rows box) still applies. When it cuts the result, the status line says row limit reached. ALIMITbelow the cap is not reported as cut.
14. Comments, quoting, semicolons
-- a line comment (needs a space after --)
# also a line comment
/* a block comment */
SELECT `t`.`sp_date`, u.`sp_user_email` -- backticks around any name
FROM `sp_db_auth`.`tsp_sys_users` AS u
JOIN tsp_time_manager t ON t.sp_user_uid = u.sp_user_uid; -- one trailing ; is fine
Executable comments /*! … */ are refused.
15. EXPLAIN
Press Explain on a cross-database query to see the plan without running it.
The Engine join plan tab has one row per table, then a final row for the work done in PHP:
| step | alias | database | table | join | fields | rows |
|---|---|---|---|---|---|---|
| 1 | t | sp_db_datamanager | tsp_time_manager | primary | sp_user_uid, sp_start_time | LIMIT 1001 |
| 2 | u | sp_db_auth | tsp_sys_users | LEFT JOIN ON u.sp_user_uid=t.sp_user_uid | sp_user_uid, sp_user_email | key lookup (IN, 500 per query) |
| 3 | merge + WHERE in PHP | sort, limit 50 |
The fields column lists every column that is read: the ones you selected,
plus join keys and WHERE / ORDER BY columns. The extra ones are dropped
before you see the result.
The JSON plan tab shows the exact Query Executor definition: the
definition_json tables, math_config (filters and options) and the steps
done after fetching. It is useful to:
- check how a
WHEREwas translated; - copy the tables into a saved Query Executor query by hand.
16. Hidden (credential) columns
A column cannot be selected, filtered on, sorted by or joined on through this route when its name:
- contains password, secret or token anywhere
(
sp_user_password,api_secret_key,reset_tokens), or - has one of these words, separated by
_or other non-letters:pass,passwd,pwd,salt,hash,hashed,otp,totp,2fa,mfa,recovery,private,secrets,tokens(for examplesp_pass_hash,sp_2fa_seed,sp_recovery_codes,private_key).
What happens:
SELECT u.sp_user_password FROM sp_db_auth.tsp_sys_users u
-- ✗ Column 'u.sp_user_password' holds credentials and cannot be read in cross-database queries.
SELECT u.* FROM sp_db_auth.tsp_sys_users u
-- ✓ runs; the column is left out, and Messages says:
-- Note ENGINE_JOIN: Left out of u.* because they hold credentials: sp_user_password.
To hide more columns, list them (or words) in
SQL_EDITOR_CROSSDB_HIDDEN_COLUMNS (§21).
This only applies to cross-database queries. On the normal path, connected to the auth database, MySQL's own grants decide what you can read.
17. Limits and how results can differ from MySQL
17.1 The scan limit
Some steps need the whole matching set before they can answer. These are
done over at most 20,000 rows of the first table
(SQL_EDITOR_CROSSDB_SCAN_ROWS):
- sorting;
- grouping and aggregates;
DISTINCT;OFFSET;- conditions on joined tables;
INNER JOIN.
When the first table has more rows than that, the editor warns:
Warning ENGINE_JOIN_SCAN: Sorting, grouping, paging and filters on joined tables are
applied to at most 20000 rows of 'tsp_time_manager' (it has 85000). Results may be
incomplete; add WHERE conditions on 't' columns, or raise SQL_EDITOR_CROSSDB_SCAN_ROWS.
How to avoid it:
- put the table you can filter most on first;
- add
WHEREconditions on that table's own columns (dates, groups, ids). They run in its database before the scan.
-- the scan only sees October's rows of t
SELECT u.sp_user_group, SUM(t.sp_duration)
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date BETWEEN '2026-10-01' AND '2026-10-31'
GROUP BY u.sp_user_group
A plain query (no sort, group, distinct, offset, joined-table condition or INNER JOIN) is not affected; it just reads the first rows up to the row cap.
17.2 Text comparison
| Comparison | Here | MySQL (default collation) |
|---|---|---|
=, !=, IN, NOT IN with text | case-insensitive | case-insensitive |
LIKE | case-insensitive | case-insensitive |
= with text containing %, _ or \ | exact (case-sensitive) | case-insensitive |
<, >, <=, >=, BETWEEN on text | case-sensitive | case-insensitive |
ORDER BY, MIN/MAX on text | case-insensitive | case-insensitive |
Dates and numbers are not affected.
17.3 Other differences
- No server time limit.
SQL_EDITOR_TIMEOUT_MSdoes not apply here, because the queries run on the engine's own connections. Filter the first table to keep queries quick. - Read only. Only
SELECT, whatever editor mode (Read/Write) is selected. - Column types. The grid's column header shows
AGGREGATEfor aggregate columns and no MySQL type for the others. - Trailing spaces. MySQL treats
'abc '='abc'; here they differ.
18. What is not supported (and what to write instead)
| Not supported | Write instead |
|---|---|
Functions in SELECT (UPPER, DATE, CONCAT, ROUND, IFNULL…) | Select the plain column; transform it after export or in a saved query's calculations |
Arithmetic in SELECT (t.a * 2, t.a + t.b) | Same as above |
Literals in SELECT (SELECT 1, 'x') | — |
CASE … END | — |
Functions or arithmetic in WHERE (WHERE DATE(t.x) = …) | A range on the raw column: t.x >= '2026-10-14' AND t.x < '2026-10-15' |
Comparing two columns in WHERE (t.a = u.b, t.a > t.b) | Joins: JOIN … ON. Same-table comparisons: not available. |
Subqueries (IN (SELECT …), FROM (SELECT …), EXISTS) | A JOIN, or two queries (§20.4) |
UNION, INTERSECT, EXCEPT | Run the queries separately |
WITH (CTEs) | The statement is not a SELECT, so it takes the normal path (CROSS_SCHEMA error) |
HAVING | ORDER BY the aggregate, then look at the top / bottom |
WITH ROLLUP | A second query without GROUP BY |
RIGHT / FULL / CROSS / NATURAL joins, USING, comma joins | LEFT / INNER JOIN … ON a.x = b.y |
More than one condition in ON | Extra conditions in WHERE |
REGEXP, RLIKE, SOUNDS LIKE, XOR, <=>, LIKE … ESCAPE | LIKE, IN, AND / OR |
NULLS FIRST / NULLS LAST | NULL sorts first in ASC, last in DESC |
database.table.column | alias.column |
FOR UPDATE, LOCK IN SHARE MODE, INTO … | — |
SQL_CALC_FOUND_ROWS, HIGH_PRIORITY, STRAIGHT_JOIN, SQL_NO_CACHE… | Remove them |
| Run script with several statements | Select one statement and press Run |
19. Error messages
Errors appear in the Messages tab with the code
EDITOR / CROSS_DB_…, a hint, and a Go to line N link when the problem
is on a specific line.
| Code | Meaning |
|---|---|
CROSS_DB_UNSUPPORTED | The SQL uses something this route cannot do. The message says what (table below). |
CROSS_DB_FAILED | The query was understood, but running it failed: a connection problem, or a database error. The database's message is shown. |
CROSS_DB_UNAVAILABLE | A required engine file is missing on the server. The message lists which ones, e.g. QueryExecuterApp::runAdhocDefinition, or MultiTable (core update …). |
CROSS_SCHEMA | Not this route at all: the query went down the normal path (see §2 for why). |
Common CROSS_DB_UNSUPPORTED messages and fixes:
| Message (shortened) | Fix |
|---|---|
Functions such as UPPER() are not supported… | Select the plain column |
Expressions are not supported in the select list… | Remove + - * / etc. |
Only columns, alias.*, and COUNT/SUM/AVG/MIN/MAX(column) can be selected… | Same |
Unknown table alias 'x'. | Check the alias spelling / that the table is in FROM/JOIN |
Unknown column 't.nope' (table tsp_time_manager). | Check the column name |
Column 'sp_user_uid' is in more than one table (t, u); qualify it… | Write t.sp_user_uid |
Column 'u.sp_user_password' holds credentials… | See §16 |
'elsewhere' is not one of the engine databases (…). | Use a database from the list in the message |
'tsp_x' has no database name, and the editor's database ('…') is not one of the engine databases. | Write database.table |
Table 'sp_db_auth.tsp_x' was not found, or cannot be read. | Check the table name, or that the database is reachable |
Joins must be a single equality: ON b.column = a.column. | Fix the ON |
Only one condition is supported in a cross-database ON clause… | Move extras to WHERE |
Qualify the columns in ON with their table alias… | ON u.x = t.x |
The ON clause must compare 'u' with a table joined before it. | Join order / aliases |
RIGHT joins are not supported… / Comma joins are not supported… | See §5.6 |
JOIN … USING is not supported; write ON b.col = a.col. | — |
Comparing two columns is not supported in a cross-database WHERE… | Use JOIN … ON |
Use IS NULL / IS NOT NULL to test for NULL. | = NULL → IS NULL |
NULL inside IN (…) is not supported; use IS NULL. | x IN ('a') OR x IS NULL |
Subqueries are not supported… | See §20.4 |
HAVING is not supported… | See §10.5 |
'…' is selected but is neither in GROUP BY nor inside an aggregate. | Add it to GROUP BY or wrap it in an aggregate |
ORDER BY …: in a grouped query, sort by a GROUP BY column or a selected aggregate. | — |
ORDER BY COUNT(*): select that aggregate too… | Add it to the select list |
SUM(*) is not valid; use SUM(column). | — |
LIMIT needs a whole number. | — |
Parameter ?#2 has no value. / Parameter :who has no value. | Fill in the parameter dialog |
The alias 'u' is used twice. | Rename one |
'u__x' cannot be used as a table alias here… | No double underscores |
Expected FROM near '…' / Unexpected '…' | Something unsupported at that spot (often CASE, a literal, or a typo) |
20. Recipes
20.1 Who is clocked in right now, with their email
SELECT u.sp_user_firstname, u.sp_user_email, t.sp_start_time
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_log_active = 1
AND t.sp_date = :today
ORDER BY t.sp_start_time
20.2 Logs whose user no longer exists
SELECT t.sp_time_log_id, t.sp_user_uid, t.sp_date
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE u.sp_user_uid IS NULL
20.3 Users in a group who have no log on a day (anti-join)
Start from the users and LEFT JOIN the logs. Keep the day condition out of
WHERE (it would remove the empty matches), so check it in a second
query, or use the log table's own key:
-- users of the group with no log at all
SELECT u.sp_user_uid, u.sp_user_email
FROM sp_db_auth.tsp_sys_users u
LEFT JOIN tsp_time_manager t ON t.sp_user_uid = u.sp_user_uid
WHERE u.sp_user_group = 'LibraryDepartment'
AND t.sp_time_log_id IS NULL
"No log today" needs the day inside the join, which
ONcannot hold. Instead, run §20.1 for the day to get who did log, and compare.
20.4 Instead of IN (SELECT …)
WHERE t.sp_user_uid IN (SELECT sp_user_uid FROM auth.users WHERE group = 'X')
is a join:
SELECT t.*
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE u.sp_user_group = 'X'
If the inner query could match several rows per key, add DISTINCT.
20.5 Totals per group for a month
SELECT u.sp_user_group AS grp,
COUNT(*) AS logs,
COUNT(DISTINCT t.sp_user_uid) AS people,
SUM(t.sp_duration) AS minutes,
AVG(t.sp_duration) AS avg_minutes
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date BETWEEN '2026-10-01' AND '2026-10-31'
GROUP BY grp
ORDER BY minutes DESC
For several months side by side, run this query once per month: grouping by
LEFT(t.sp_date, 7) is not possible.
20.6 Top 10 users by time this week
SELECT u.sp_user_firstname, u.sp_user_email, SUM(t.sp_duration) AS minutes
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date BETWEEN ? AND ?
GROUP BY u.sp_user_firstname, u.sp_user_email
ORDER BY minutes DESC
LIMIT 10
20.7 Daily headcount per group
SELECT t.sp_date, u.sp_user_group, COUNT(DISTINCT t.sp_user_uid) AS people
FROM tsp_time_manager t
JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date >= '2026-10-01'
GROUP BY t.sp_date, u.sp_user_group
ORDER BY t.sp_date, u.sp_user_group
20.8 Search users by part of a name or email (case-insensitive)
SELECT u.sp_user_uid, u.sp_user_firstname, u.sp_user_email
FROM sp_db_auth.tsp_sys_users u
WHERE u.sp_user_firstname LIKE :q OR u.sp_user_email LIKE :q
ORDER BY u.sp_user_firstname
-- in the parameter dialog: q = %ann%
20.9 Paging through a large join
SELECT t.sp_time_log_id, t.sp_date, u.sp_user_email
FROM tsp_time_manager t
LEFT JOIN sp_db_auth.tsp_sys_users u ON u.sp_user_uid = t.sp_user_uid
WHERE t.sp_date >= :from -- keeps the scan small (§17.1)
ORDER BY t.sp_time_log_id
LIMIT 100 OFFSET :skip -- 0, 100, 200, …
20.10 Users with their permission row (three tables)
SELECT u.sp_user_email, s.can_select_data, s.can_update_data, s.can_delete_data
FROM sp_db_auth.tsp_sys_users u
LEFT JOIN sp_db_auth.tsp_sys_security s ON s.sp_user_uid = u.sp_user_uid
WHERE u.sp_user_group = 'LibraryDepartment'
ORDER BY u.sp_user_email
(All tables from one other database also take this route.)
21. Settings (.env)
All are optional.
# Turn the feature off (the CROSS_SCHEMA error comes back)
SQL_EDITOR_CROSS_DB=true
# How many rows of the first table are read when sorting, grouping, DISTINCT,
# OFFSET, joined-table filters or INNER JOIN are involved (100–200000)
SQL_EDITOR_CROSSDB_SCAN_ROWS=20000
# Extra columns that may not be read, comma separated.
# Whole names (exact) or words (matched between underscores):
SQL_EDITOR_CROSSDB_HIDDEN_COLUMNS=sp_user_phone,birthdate,ssn
The editor's existing settings apply as well:
| Setting | Effect here |
|---|---|
SQL_EDITOR_ENABLED | Must be true |
SQL_EDITOR_MAX_ROWS | Row cap of the result |
SQL_EDITOR_MAX_CELL_BYTES | Long cells are cut for display |
SQL_EDITOR_MAX_RESULT_BYTES | Size cap of the result |
SQL_EDITOR_MAX_SQL_BYTES | Size cap of the SQL text |
SQL_EDITOR_AUDIT_SQL | Whether the SQL text is in the audit log line |
Every run writes one audit line (route: crossdb) with the user, the tables,
the row count and any error code.
Who can use it: the same people as the SQL editor (administrators and the system root). The Query Executor checks again before running.
22. Cheat sheet
SELECT [DISTINCT]
a.col [AS name], b.col, a.*, *,
COUNT(*), COUNT([DISTINCT] a.col), SUM([DISTINCT] a.col),
AVG([DISTINCT] a.col), MIN(a.col), MAX(a.col)
FROM [db.]table [AS] a
[LEFT [OUTER] | INNER] JOIN [db.]table [AS] b ON b.col = a.col
... -- any number of joins
WHERE a.col =|!=|<>|<|>|<=|>= value
a.col [NOT] IN (v1, v2, ...)
a.col [NOT] BETWEEN v1 AND v2
a.col [NOT] LIKE 'pattern%'
a.col IS [NOT] NULL
value op a.col
combined with AND (&&), OR (||), NOT (!), ( )
GROUP BY a.col | name | position, ...
ORDER BY a.col | name | 'quoted name' | position | AGG(...) [ASC|DESC], ...
LIMIT n [OFFSET m] | LIMIT m, n -- numbers or ? / :name
dbis a physical name (u123456789_sp_db_auth) or a handle (sp_db_auth). Leave it out for the editor's own database.- Values are
'text',"text", numbers,TRUE,FALSE,?or:name. - Press Run (not Run script). Explain shows the plan.