从具有连接的两个表中删除

时间:2013-12-15 02:28:28

标签: mysql join sql-delete

我有疑问:

SELECT *
FROM `phpbb_posts` AS a
JOIN phpbb_posts_text AS b ON a.post_id = b.post_id
WHERE a.poster_id =5413

它给了我X行数,我想要一个将删除所有这些行的查询(我不需要先选择那只是JOIN的一个例子。

任何帮助?

2 个答案:

答案 0 :(得分:4)

这很简单。

DELETE a, b    
FROM `phpbb_posts` AS a
JOIN phpbb_posts_text AS b ON a.post_id = b.post_id
WHERE a.poster_id =5413

答案 1 :(得分:0)

您可以单独删除每个表

DELETE b
FROM phpbb_posts_text AS b
INNER JOIN `phpbb_posts` AS a 
     ON 
          a.post_id = b.post_id
     AND  a.poster_id =5413

DELETE a
FROM `phpbb_posts` AS a
WHERE a.poster_id =5413

第二个可以写成

DELETE `phpbb_posts` 
WHERE poster_id =5413