[英]sql Inner join delete
I have tow tables 我有拖车桌
tests_sub ,tests_sub_sub tests_sub,tests_sub_sub
and tests_sub.id = tests_sub_sub.id
和tests_sub.id = tests_sub_sub.id
so i want to delete data from both tables with one 所以我想从两个表中删除一个数据
sql query sql查询
I used the following inner join 我使用了以下内部联接
DELETE tests_sub, tests_sub_sub FROM tests_sub
INNER JOIN tests_sub_sub ON tests_sub_sub.id = tests_sub.id
WHERE tests_sub.id = 10
the query works ok only if both tables have entries for the tests_sub.id... ( if tests_sub_sub has no entry for test_sub.id = 10 ... although the table tests_sub has entries for that id no rows are affected ... please suggest some tips.... 仅当两个表都具有tests_sub.id的条目时该查询才能正常运行... ...(如果tests_sub_sub没有为test_sub.id的条目= 10 ...尽管表tests_sub具有该id的条目,则不影响任何行...请建议一些技巧。
use LEFT JOIN
. 使用LEFT JOIN
。
DELETE tests_sub, tests_sub_sub
FROM tests_sub
LEFT JOIN tests_sub_sub
ON tests_sub_sub.id = tests_sub.id
WHERE tests_sub.id = 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.