mysql删除与交叉表查找

时间:2014-04-28 13:18:36

标签: mysql sql

SQL

DELETE FROM sex s, users u WHERE s.id = 195 and u.id = s.uid and u.sessionCheck = 'd986a074c7549c566bfed1d4ad7ca491'

错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's, users u WHERE s.id = 195 and u.id = s.uid and u.sessionCheck = 'd986a074c7549' at line 1

很明显错误在于删除中的连接。但是我所尝试的一切都无济于事。

我正在使用Server version: 5.6.16 - MySQL Community Server (GPL)

3 个答案:

答案 0 :(得分:3)

DELETE s /* forgot to mention from which table you like to delete from these 2 */
FROM sex s
join users u on u.id = s.uid 
WHERE s.id = 195
and u.sessionCheck = 'd986a074c7549c566bfed1d4ad7ca491'

答案 1 :(得分:0)

DELETE s.* FROM sex s,users u   WHERE u.id = s.uid AND s.id = 195 AND u.sessionCheck = 'd986a074c7549c566bfed1d4ad7ca491'

答案 2 :(得分:0)

DELETE FROM sex 
WHERE sex.id IN (SELECT id 
                 FROM users u
                 WHERE u.sessionCheck = 'd986a074c7549c566bfed1d4ad7ca491')

从两个表中删除

DELETE s.*,u.*
FROM sex s
inner join users u on u.id = s.uid 
WHERE s.id = 195
and u.sessionCheck = 'd986a074c7549c566bfed1d4ad7ca491'