首页 > mysql 联表查询

mysql 联表查询

A表        order_id         data
             1                 1
             2                 2
             3                 3

B表        order_id         state
             1                1
             2                2
             
             
             

查找A中与B不重复的对应order_id的data(即order_id=3的data),sql语句怎么写?


select data
from A left join B on A.order_id = B.order_id
where isnull(B.state)


select data from A where A.id not IN (select B.id from B)


SELECT a.data FROM a LEFT JOIN b ON a.order_id=b.order_id WHERE b.order_id IS NULL

select data from a where not exists (select 1 from b where a.order_id = b.order_id)

select data from a 
where order_id not in (
  select distinct order_id from b 
);

select * from A where order_id not in (select order_id from B)
【热门文章】
【热门文章】