What does the MySQL USING
statement do and is there any docs on this?
MySQL USING statement example
DELETE FROM l, s
USING l
INNER JOIN s ON s.skill_id = l.id
WHERE s.user_id = 3
The DELETE statement is used to delete existing records in a table.
To remove a table in MySQL, use the DROP TABLE statement. The basic syntax of the command is as follows: DROP [TEMPORARY] TABLE [IF EXISTS] table_name [, table_name] [RESTRICT | CASCADE];
The MySQL DELETE statement is used to delete a single record or multiple records from a table in MySQL.
You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the condition in the WHERE clause. You cannot use ORDER BY or LIMIT in a multiple-table DELETE .
In a DELETE, you can list tables after the USING clause, from which rows do not get deleted (i.e., to only be part of the WHERE clause). For example:
DELETE FROM t1, t2
USING t1
INNER JOIN t2
INNER JOIN t3
WHERE t1.id=t2.id AND
t2.id=t3.id;
Your particular example can be achieved without USING in this fashion:
DELETE l,s
FROM l
INNER JOIN s
ON s.skill_id = l.id
WHERE s.user_id = 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With