2个查询的比较(MySQL)

时间:2014-12-04 10:07:51

标签: mysql sql

我有两个问题。它们是一样的吗?

DELETE FROM t1 
USING t1 
LEFT JOIN t2 using(key) 
WHERE t2.key is null

DELETE t1 
FROM t1  
LEFT JOIN t2 using(key) 
WHERE t2.key is null

如果是,哪一个更有效?

1 个答案:

答案 0 :(得分:0)

在我看来,两者都是相同的,因为我从这个语法中知道:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

多表语法:

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

或者:

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

关注哪一个更有效率?这取决于情况意味着我们何时何地使用它。

阅读本文以获得更好的体验:http://dev.mysql.com/doc/refman/5.1/en/delete.html