I thought this should work, but as you can see I'm getting an error. The goal here is to delete duplicates by defining duplicates using two columns. The first list is all the dupes, the second list uses the row ID to ensure that one of each duplicate set is kept. Help!
DELETE FROM tbl_events_temp WHERE tbl_events_temp.event_id IN (
SELECT F.event_id
FROM tbl_events_temp AS F
WHERE EXISTS (
SELECT airport_id, event_from, Count( event_id )
FROM tbl_events_temp
WHERE tbl_events_temp.airport_id = F.airport_id
AND tbl_events_temp.event_from = F.event_from
AND tbl_events_temp.airport_id != ''
GROUP BY tbl_events_temp.airport_id, tbl_events_temp.event_from
HAVING Count( tbl_events_temp.event_id ) >1
)
)
AND tbl_events_temp.event_id NOT
IN (
SELECT Min( event_id )
FROM tbl_events_temp AS F
WHERE EXISTS (
SELECT airport_id, event_from, Count( event_id )
FROM tbl_events_temp
WHERE tbl_events_temp.airport_id = F.airport_id
AND tbl_events_temp.event_from = F.event_from
GROUP BY tbl_events_temp.airport_id, tbl_events_temp.event_from
HAVING Count( tbl_events_temp.event_id ) >1
)
GROUP BY airport_id, event_from
)
Error:
MySQL said: Documentation
#1093 - You can't specify target table 'tbl_events_temp' for update in FROM clause