Mysql select where not in table

前端 未结 5 1699
离开以前
离开以前 2020-11-29 21:46

I have 2 tables (A and B) with the same primary keys. I want to select all row that are in A and not in B. The following works:

select * from A where not exi         


        
5条回答
  •  孤独总比滥情好
    2020-11-29 22:18

    This helped me a lot. Joins are always faster than Sub Queries to give results:

    SELECT tbl1.id FROM tbl1 t1
    LEFT OUTER JOIN tbl2 t2 ON t1.id = t2.id 
    WHERE t1.id>=100 AND t2.id IS NULL ;
    

提交回复
热议问题