- delete from sns_hits where id not in (1,2,3)
- delete from sns_hits where id not in (select id from another_table)
但是
- delete from sns_hits where id not in (select id from sns_hits)
解決棒法是創建臨時表
- CREATE TEMPORARY TABLE tmp_sns_hits (
- `id` BIGINT(20)
- )
DELETE from user WHERE id not in (SELECT * from (SELECT id from user u WHERE u.id>4)u)