0

微优化我知道,这更多是因为我好奇。

我有两个链接表,

blog_categories_posts => post_id, category_id  
blog_tags_posts       => post_id, tag_id

我根据以下内容从两个表中删除所有链接post_id

DELETE FROM blog_categories_posts WHERE post_id = {$id};
DELETE FROM blog_tags_posts WHERE post_id = {$id};

无论如何,我想知道是否可以同时从两个表中删除,以及它是否会是性能(虽然是微的)命中或增益?

我想如果它起作用:

DELETE FROM blog_categories_posts, blog_tags_posts where post_id = {$id} 

或类似的语法?

4

1 回答 1

0

语法在mysql网站上:删除语法

DELETE FROM tbl1, tbl2
USING tbl1
JOIN tb2 USING (id)
WHERE id = :id

因此,对于您的示例,它将是:

DELETE FROM blog_categories_posts, blog_tags_posts
USING blog_categories_posts
JOIN blog_tags_posts USING (post_id)
WHERE post_id = $id

添加许多表也很容易:

DELETE FROM tbl1, tbl2, tbl3, tbl4, tbl5
USING tbl1
JOIN tb2 USING (id)
JOIN tb3 USING (id)
JOIN tb4 USING (id)
JOIN tb5 USING (id)
WHERE id = :id
于 2013-06-06T15:45:28.420 回答