MySQL加入而不是子查询

时间:2013-01-25 12:40:59

标签: mysql sql sql-delete

嘿伙计们我想要这样的事情:

DELETE FROM ClientsFlags 
WHERE clientId = (SELECT id 
                  FROM Client 
                  WHERE emailRegistrationToken = 3) 
AND flagId = 42;

但是使用连接而不是子查询。我对加入不是很好,所以请帮助我。

3 个答案:

答案 0 :(得分:1)

这是一个加入版本,

DELETE  a
FROM    ClientsFlags a
        INNER JOIN Client b
            ON a.clientId = b.id
WHERE   b.emailRegistrationToken = 3 AND            
        a.flagId = 42;

答案 1 :(得分:1)

试试这个

Delete C From ClientFlags cf, Client c where cf.lientId=c.Id and email=3 and flagId=42;

答案 2 :(得分:0)

你应该尝试这样的事情:

 DELETE C FROM ClientsFlags AS CF
 JOIN Client AS C ON C.Id=CF.clientId 
 WHERE email=3 and flagId=42