Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the MySQL USING statement do in conjunction with DELETE?

Tags:

mysql

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
like image 997
HELP Avatar asked Oct 19 '10 16:10

HELP


People also ask

What is the use of delete command in MySQL?

The DELETE statement is used to delete existing records in a table.

Which statement is used to delete a table in MySQL?

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];

Which statement is used to all delete records from a table in MySQL?

The MySQL DELETE statement is used to delete a single record or multiple records from a table in MySQL.

Can we use ORDER BY in delete query?

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 .


1 Answers

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 
like image 158
Michael Goldshteyn Avatar answered Sep 19 '22 01:09

Michael Goldshteyn