Reputation: 2203
I have two tables, events
and locations
. Each has a column named venue_id
to match an event to the correct location. venue_id
is not the primary key.
What query could I run to delete the rows in locations
that have no event linked to them?
Upvotes: 0
Views: 71
Reputation: 91666
Maybe something like:
DELETE FROM Locations where venue_id not in
(select distinct venue_id from Events);
Upvotes: 1
Reputation: 186
This should do it :
DELETE FROM locations WHERE venue_id
NOT IN (SELECT DISTINCT venue_id FROM events)
Upvotes: 3