蔭嘗試這樣做如何編寫查詢A(表)工會B(表)在MySQL相交C(表)
select Barcode from ITList union select Barcode from Equipment_list
intersect select Barcode from Scanneditem
蔭嘗試這樣做如何編寫查詢A(表)工會B(表)在MySQL相交C(表)
select Barcode from ITList union select Barcode from Equipment_list
intersect select Barcode from Scanneditem
檢查:
SELECT a.Barcode FROM Scanneditem AS a
JOIN (SELECT Barcode FROM ITList UNION SELECT Barcode FROM Equipment_list) AS b
ON a.Barcode=b.Barcode;
您可以使用exists此
Select * from (select Barcode from ITList union select Barcode from Equipment_list) as t
where exists (select Barcode from Scanneditem where Scanneditem.Barcode = t.Barcode)
此查詢顯示錯誤「ERROR 1064(42000):您的SQL語法錯誤;請查看與您的MySQL服務器版本相對應的手冊,以找到正確語法,以便在'Scanneditem where Scanneditem.Barcode = t'中選擇條形碼。條形碼)'在第1行「 –
@ varadharajanp.rRajan如果您對此答案有疑問,您爲什麼接受它?請只接受適合您的答案。 – cybermonkey
iam新增到stackoverflow,所以很不幸我做了 –
雖然在MySQL沒有INTERSECT操作,您可以使用IN子句或EXISTS子句,這取決於o輕鬆地模擬這種類型的查詢INTERSECT查詢的複雜性。
請試試這個:
SELECT * FROM (SELECT Barcode FROM ITList UNION SELECT Barcode FROM Equipment_list) AS allbarcode
WHERE allbarcode.Barcode IN (SELECT Barcode FROM Scanneditem)
您還可以查看納文戈亞爾SQL與EXISTS子句(下面的回覆)。
這是打印什麼,我已經在scanningitem類,但我想除了這個條形碼從ITList和Equipmetlist表 –
MySQL>從scanneritem選擇條形碼; + --------- + |條碼| + --------- + | HCL78 | | ACCE78 | + --------- + 設置2行(0.00秒) mysql>從ITList聯合選擇條形碼從Equipment_List選擇條形碼; + ----------- + |條碼| + ----------- + | HCL78 | | ACCE78 | | ERTUYS | | WWERT | | IOWREUIR | | DELL78 | | IOERP | | 23423uiuf | + ----------- + 集合中的8行(0.00秒) –
我想除了掃描的項目類數據。 –
此查詢顯示此錯誤錯誤1052(23000):字段列表中的列'條碼'含糊不清 –
您可以使用a.barcode或b.barcode。 –