作者su9958 (su9958)
看板Database
標題[討論] 在查詢上遇到瓶頸
時間Mon Apr 17 00:02:30 2017
這次希望可以做到一個功能是
在群組新增會員名單 可以不出現已經加入群組的會員
目前有一張資料表稱為t1 他儲存著會員資料
而t2分為群組編號 會員編號 加入者編號
現在是下
select * from user as t1 join group_user as t2 where t2.id=t1.id;
但好像不一定能達到我要的效果
請問該怎麼下才對 又或者在資料表上我能重新做什麼樣的安排
先謝謝各位了
--
Sent from my Windows
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.115.113.239
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Database/M.1492358553.A.0F7.html
1F:推 SeanBoog: Not in 04/17 00:09
2F:→ moyasi: not in not exists都可以吧 04/17 11:15
3F:→ streetbad: 查詢結果要的是!? 不要出現已有群組的會員!? 04/17 14:23
4F:→ su9958: 查詢結果要的是可以加入群組的會員列表 去除掉已在此群組 04/18 11:12
5F:→ su9958: 的會員 用not in一下可以一下又會錯 謝謝 04/18 11:12
6F:推 streetbad: select t1.* from t1 04/18 11:36
7F:→ streetbad: left outer join t2 on t2.ano = t1.ano 04/18 11:36
8F:→ streetbad: where t2.ano is null 04/18 11:36
9F:→ streetbad: 找出不存在於t2的t1會員編號與其資料 不確定是否 04/18 11:37
10F:→ streetbad: 符合你的需求 04/18 11:37