Jump to content

how to delete from multiple tables if some may not exist


onedumbcoder

Recommended Posts

lets say i have 10 tables

 

a b c d e f g h i j

 

a has and id

 

the rest have a a_id as afield

 

i want to delete a, and any of the other ones that might exist and have an a_id of the a i am deleting.

 

i do not want to do 10 queries  and i cant quite figure out how to use the correct syntax for one query can someone please help me.

 

 

:'(

I'm looking for something like this:

 DELETE FROM a left join b,c,d,e,f WHERE a.id='sdf'=b.aid=c.aid=d.aid=e.aid=f.aid

 

im just looking for the right syntax.

 

i dont want to do this

 DELETE FROM a WHERE id='asd'
DELETE FROM b WHERE aid='asd'
DELETE FROM c WHERE aid='asd'
DELETE FROM d WHERE aid='asd'
DELETE FROM e WHERE aid='asd'
DELETE FROM f WHERE aid='asd'

 

 

 

 

How about:

 

DELETE 
a, b, c, d, e, f 
FROM a 
left join b on ( a.id=b.aid )
left join c on ( a.id=c.aid )
left join d on ( a.id=d.aid )
left join e on ( a.id=e.aid )
left join f on ( a.id=f.aid )
WHERE a.id='sdf'

 

But I think there might be something wrongwith your table structure.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.