![](/img/trans.png)
[英]How to select records from one table where values from all the records in a column of second table match any of the multiple columns of first table?
[英]Mysql How to select all records from one table where column value is not both X and Y
我有一個包含三列的表:
customerID (Autoincrement INT)
ShopID (INT)
GroupID (INT)
EmailAddress (varchar)
Password (varchar)
所以假設 GroupID = 2 並且我有兩個 shopID(25 和 26)
我需要選擇客戶在 GroupID 2 但只有一個 ShopID 中的所有記錄,並為該 sme 客戶插入一條新記錄(使用新的 customerID 但他的其他數據),以便他可以登錄兩個商店使用相同的電子郵件地址和密碼。
任何人都可以幫助我如何選擇不屬於兩家商店的所有客戶 ID?
您可以嘗試使用相關子查詢
select customerid from tablename a
where not exists
(select 1 from tablename b where a.customerid=b.customerid
and shopid in (25,26) group by customerid having count(distinct shopid)=2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.