文章詳情頁
mysql 聯表查詢
瀏覽:154日期: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)
相關文章:
1. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙2. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?3. linux運維 - python遠程控制windows如何實現4. Python2中code.co_kwonlyargcount的等效寫法5. python - 如何對列表中的列表進行頻率統計?6. django - Python error: [Errno 99] Cannot assign requested address7. mysql數據庫做關聯一般用id還是用戶名8. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?9. python小白,關于函數問題10. python小白 關于類里面的方法獲取變量失敗的問題
排行榜
