Jeremy
Jeremy

Reputation: 973

Delete from two tables with join

I am having a query :

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

It gives me X number of rows, and I want a query that will delete all these rows (I don't need to select first that was just an example for the JOIN.

Any help ?

Upvotes: 0

Views: 68

Answers (2)

Jason Heo
Jason Heo

Reputation: 10236

It's so simple.

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

Upvotes: 4

Preet Sangha
Preet Sangha

Reputation: 65476

You can delete each table separately

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

the second can written as

DELETE `phpbb_posts` 
WHERE poster_id =5413

Upvotes: 0

Related Questions