tags:

views:

50

answers:

4

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
A: 

The USING clause is used to set column existence criteria for two tables in a JOIN.

So, if I have a statement such as:

SELECT * from a
JOIN b
USING (c1,c2)
...

what will happen is that the MySQL engine will first verify that columns c1 and c2 exist in both tables, and then compare the values of those columns to perform the join on the two tables.

See MySQL documentation for JOIN Syntax.

Brian Driscoll
That is another use of the USING statement, but not the one he is referring to in his question.
Eric Petroelje
LOL wow I'm 0 for 2 today on reading what OPs are actually asking...
Brian Driscoll
+2  A: 

Search for USING in the MySQL documentation for DELETE. It is just an alternative syntax.

ar
+3  A: 

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 
Michael Goldshteyn
A: 

Syntax for USING statement -

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
    FROM tbl_name[.*] [, tbl_name[.*]] ...
    USING table_references
    [WHERE where_condition]

for detailed info visit USING

Alpesh
No, the use of `USING` in the question is part of the multi-table DELETE syntax.
ar
Yes updated my code according to that. :)
Alpesh