在两个表上使用交叉?

时间:2022-08-11 20:32:59

I am trying to find the rows that all four tables share in common. I tried using this:

我试图找到所有4个表共享的行。我试着用这个:

SELECT * 
FROM TABLE1 
INTERSECT
SELECT *
FROM TABLE2
INTERSECT
SELECT *
FROM TABLE3
 INTERSECT
SELECT *
FROM TABLE4;    

But got no results, i know there are rows that meet this requirement. Because using union instead and adding "order by" i see four rows with the same description from different tables.

但是没有结果,我知道有行满足这个要求。因为使用union而不是添加“order by”,我可以从不同的表中看到四行相同的描述。

1 个解决方案

#1


5  

Use INNER JOIN with conditions on the fields that you want
ex:

在你想要的字段中使用内部连接:

SELECT 
    t1.* 
FROM 
    TABLE1 t1
INNER JOIN TABLE2 t2
    ON t1.field1 = t2.field1
    AND t1.field2 = t2.field2
    ...
INNER JOIN TABLE2 t3
    ON t1.field1 = t3.field1
    AND t1.field2 = t3.field2
...

#1


5  

Use INNER JOIN with conditions on the fields that you want
ex:

在你想要的字段中使用内部连接:

SELECT 
    t1.* 
FROM 
    TABLE1 t1
INNER JOIN TABLE2 t2
    ON t1.field1 = t2.field1
    AND t1.field2 = t2.field2
    ...
INNER JOIN TABLE2 t3
    ON t1.field1 = t3.field1
    AND t1.field2 = t3.field2
...