mysql - Two tables - how to delete rows if ID not referenced in both tables -


i have 2 tables:

listings(item_id, ...) images(item_id,  ...) 

the item_id value same in both tables - goofed , deleted listings 'listings' table without deleting corresponding row in 'images' table.

so - want delete rows in second 'images' table if item_id in images doesn't correspond of more up-to-date item_id values in primary 'listings' table.

how delete records in 'images' table not referenced 'listings'?

i've been experimenting sql script , sub-query this:

delete images item_id in (select item_id images except select item_id listings) 

but before screw up, want confirm if correct?

you should use sub query

delete images item_id not in(select item_id listings) 

more examples , explanation.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -