Skip to content
Article Cross-database queries in the SQL editor
☀️ Light Clean and bright
📜 Sepia Warm and vintage
🌤️ Light Gray Subtle and neutral
🔵 Light Blue Calm and serene
🌙 Dark Easy on the eyes
🌑 Dark Gray Deep and modern
🔷 Dark Blue Professional and sleek
🌿 Forest Calm and natural

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:

  1. Each table is read on its own database connection.
  2. The rows are joined by the engine (MultiTable).
  3. The engine applies your WHERE, GROUP BY, ORDER BY and LIMIT.

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, u123456789 stands for your hosting account prefix. Your real database names look like u123456789_sp_datamanager and u123456789_sp_db_auth.


Contents

  1. Quick start
  2. When a query takes this route
  3. Naming databases and tables
  4. SELECT: choosing columns
  5. JOIN
  6. WHERE: every condition you can write
  7. Values: strings, numbers, NULL, TRUE/FALSE
  8. Parameters (? and :name)
  9. Aggregates: COUNT, SUM, AVG, MIN, MAX
  10. GROUP BY
  11. DISTINCT
  12. ORDER BY
  13. LIMIT and OFFSET
  14. Comments, quoting, semicolons
  15. EXPLAIN
  16. Hidden (credential) columns
  17. Limits and how results can differ from MySQL
  18. What is not supported (and what to write instead)
  19. Error messages
  20. Recipes
  21. Settings (.env)
  22. 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:

ConditionIf not
It starts with SELECTNormal 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 ownNormal path. Plain single-database SQL runs exactly as before.
You pressed Run or Explain, and only one statement is sentRun 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 falseNormal 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_manager while 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__x is refused, because the engine uses __ internally);
  • each alias once per query (u and U count 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 = 1 keeps every t row and blanks u where x is not 1. Moving u.x = 1 to WHERE drops those rows instead. To keep them, write WHERE (u.x = 1 OR u.sp_user_uid IS NULL). That gives the same rows, except rows whose u match 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)

  1. The first table (after FROM) is read, with the WHERE conditions that only use its own columns.
  2. For each joined table, only the rows whose key matches a key already loaded are read, as WHERE key IN (…), 500 keys per query.
  3. The rows are merged in PHP, then the rest of WHERE is 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_uid and similar).

5.6 Joins that are not supported

WriteInstead
RIGHT JOIN b … Swap the tables and use LEFT JOIN: FROM b LEFT JOIN a ON …
FULL JOINNot available
CROSS JOIN, FROM a, bUse JOIN … ON
NATURAL JOINJOIN … ON b.col = a.col
JOIN … USING (col)JOIN … ON b.col = a.col
ON with two conditionsOne in ON, the rest in WHERE (see the note in §5.3)
ON a.x > b.yEquality 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' or t.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.
  • NULL is not allowed inside the list. Use IS NULL (§6.8).
  • NOT IN does 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:

WordSymbol
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

KindExamplesNotes
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 number42, -7, +3
Decimal1.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.
BooleanTRUE, FALSESame as 1 and 0.
NULLNULLOnly in IS NULL / IS NOT NULL.
Parameter?, :nameSee §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 WHERE value, including inside IN (…) and BETWEEN.
  • In LIMIT and OFFSET:
… 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

WriteResultNULLs
COUNT(*)number of rowscounted
COUNT(a.col)rows where col is not NULLskipped
COUNT(DISTINCT a.col)number of different non-NULL valuesskipped
SUM(a.col)totalskipped; NULL if there are no values
SUM(DISTINCT a.col)total of the different valuesskipped
AVG(a.col)average, rounded to 4 decimalsskipped; NULL if there are no values
AVG(DISTINCT a.col)average of the different valuesskipped
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 without GROUP BY for 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 LAST are not supported.
  • Numbers as numbers: 9 before 10, 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 BY with OFFSET for 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. A LIMIT below 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:

stepaliasdatabasetablejoinfieldsrows
1tsp_db_datamanagertsp_time_managerprimarysp_user_uid, sp_start_timeLIMIT 1001
2usp_db_authtsp_sys_usersLEFT JOIN ON u.sp_user_uid=t.sp_user_uidsp_user_uid, sp_user_emailkey lookup (IN, 500 per query)
3merge + WHERE in PHPsort, 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 WHERE was 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 example sp_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 WHERE conditions 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

ComparisonHereMySQL (default collation)
=, !=, IN, NOT IN with textcase-insensitivecase-insensitive
LIKEcase-insensitivecase-insensitive
= with text containing %, _ or \exact (case-sensitive)case-insensitive
<, >, <=, >=, BETWEEN on textcase-sensitivecase-insensitive
ORDER BY, MIN/MAX on textcase-insensitivecase-insensitive

Dates and numbers are not affected.

17.3 Other differences

  • No server time limit. SQL_EDITOR_TIMEOUT_MS does 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 AGGREGATE for 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 supportedWrite 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, EXCEPTRun the queries separately
WITH (CTEs)The statement is not a SELECT, so it takes the normal path (CROSS_SCHEMA error)
HAVINGORDER BY the aggregate, then look at the top / bottom
WITH ROLLUPA second query without GROUP BY
RIGHT / FULL / CROSS / NATURAL joins, USING, comma joinsLEFT / INNER JOIN … ON a.x = b.y
More than one condition in ONExtra conditions in WHERE
REGEXP, RLIKE, SOUNDS LIKE, XOR, <=>, LIKE … ESCAPELIKE, IN, AND / OR
NULLS FIRST / NULLS LASTNULL sorts first in ASC, last in DESC
database.table.columnalias.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 statementsSelect 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.

CodeMeaning
CROSS_DB_UNSUPPORTEDThe SQL uses something this route cannot do. The message says what (table below).
CROSS_DB_FAILEDThe query was understood, but running it failed: a connection problem, or a database error. The database's message is shown.
CROSS_DB_UNAVAILABLEA required engine file is missing on the server. The message lists which ones, e.g. QueryExecuterApp::runAdhocDefinition, or MultiTable (core update …).
CROSS_SCHEMANot 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 ON cannot 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:

SettingEffect here
SQL_EDITOR_ENABLEDMust be true
SQL_EDITOR_MAX_ROWSRow cap of the result
SQL_EDITOR_MAX_CELL_BYTESLong cells are cut for display
SQL_EDITOR_MAX_RESULT_BYTESSize cap of the result
SQL_EDITOR_MAX_SQL_BYTESSize cap of the SQL text
SQL_EDITOR_AUDIT_SQLWhether 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
  • db is 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.