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
Post a Comment