文章詳情頁
mysql 聯表查詢
瀏覽:165日期:2022-06-21 18:53:02
問題描述
A表order_id data 1 1 2 2 3 3B表order_id state 11 22
查找A中與B不重復的對應order_id的data(即order_id=3的data),sql語句怎么寫?
問題解答
回答1:select data from a where order_id not in ( select distinct order_id from b );回答2:
select datafrom A left join B on A.order_id = B.order_idwhere isnull(B.state)
回答3:select * from A where order_id not in (select order_id from B)回答4:
SELECT a.data FROM a LEFT JOIN b ON a.order_id=b.order_id WHERE b.order_id IS NULL回答5:
select data from A where A.id not IN (select B.id from B)
回答6:select data from a where not exists (select 1 from b where a.order_id = b.order_id)
相關文章:
排行榜
