I’m reviewing a MySQL query and came across a keyword I’ve never seen before – "excludes". It’s used in a DELETE statement similar to:
DELETE table_A
FROM table_A
JOIN (
SELECT DISTINCT table_A.field
FROM table_A
JOIN table_B
USING (field)
LEFT JOIN table_C
USING (field)
WHERE table_C.field IS NULL
AND table_B.amount <> 0
)
excludes USING(field)
Maybe my search query is off, but I can’t find anything on Google or in the MySQL documentation.
2
Answers
In the query you show,
excludes
is not a keyword, it’s just an alias for the derived-table subquery.Just like you can use a table alias in a query like this:
The
AS
keyword before the alias is optional.The table references syntax used in joins is documented here: https://dev.mysql.com/doc/refman/8.0/en/join.html
EXCLUDE conditions in MySQL usually appear in the WHERE clause of the statement or in the HAVING clause of an aggregate query. Some commonly used EXCLUDE operators in MySQL are NOT, NOT IN, NOT LIKE, ‘! =’, EXCEPT, NOT NULL, etc