mysql - SQL Delete on inner join on MISSING data -


my question identical sql delete inner join ; want delete on non equal!

my problem in brief: there 2 tables, bus_stops, bus_routes ;

bus_routes {id, bus_route_id,..other columns..} bus_stops {id, bus_route_id,..other columns..} 

some routes had been deleted, bus stops remaining, need delete them too. means, need delete bus_stops, have no associated bus route!

it means like:

delete bs.* bus_stops bs  inner join bus_routes br  on bs.bus_route_id <> br.bus_route_id 

but above code not work.

you should use left join, below query work:

delete bs.*   bus_stops bs  left join bus_routes br  on bs.bus_route_id = br.bus_route_id br.bus_route_id null 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -