如何在mysql中为A(表)联合B(表)与C(表)相交写查询

时间:2016-06-22 11:03:08

标签: mysql

我试着这样做

select Barcode from ITList union select Barcode from Equipment_list
intersect select Barcode from Scanneditem

3 个答案:

答案 0 :(得分:2)

检查一下:

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;

答案 1 :(得分:1)

您可以使用“存在”

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)

答案 2 :(得分:-1)

虽然MySQL中没有INTERSECT运算符,但您可以使用IN子句或EXISTS子句轻松模拟此类查询,具体取决于INTERSECT查询的复杂性。

请试试这个:

SELECT * FROM (SELECT Barcode FROM ITList UNION SELECT Barcode FROM Equipment_list) AS allbarcode 
WHERE allbarcode.Barcode IN (SELECT Barcode FROM Scanneditem)

您还可以使用EXISTS子句检查Naveen Goyal sql(下面的回复)。