select .... from table1 join table2 on table1.x = table2.y join table3 on table1.z = table3.w
我没试过,供参考: select * from ( select ...... union all select ..... union all select .....) a group by field1,field2..... having(count(*)>1)
对。你的具体情况能否用JOIN一次SELECT出来?
select * from ( select ...... ) as a inner join ( select ..... ) as b on ... inner join ( select ..... ) as c on ...
我的是错的,老兄!用JOIN才是交集! 我那个只是找出随便的两个子集的交集!
join 是交集 union 是并集
哈哈,我知道了。我的写法跟你的有一点点不同:select * from ( select ...... union all select ..... union all select .....) a group by field1,field2..... having(count(*)=n)最后这个n是select的个数,所以能得到交集(交集外的出现次数不会是n)。具体的写法也不完全是这样。当时改完就忘了回这里交代一下了。
from table1
join table2
on table1.x = table2.y
join table3
on table1.z = table3.w
select * from (
select ......
union all
select .....
union all
select .....) a
group by field1,field2..... having(count(*)>1)
(
select ......
) as a
inner join
(
select .....
) as b
on ...
inner join
(
select .....
) as c
on ...
我那个只是找出随便的两个子集的交集!
union 是并集
select ......
union all
select .....
union all
select .....) a
group by field1,field2..... having(count(*)=n)最后这个n是select的个数,所以能得到交集(交集外的出现次数不会是n)。具体的写法也不完全是这样。当时改完就忘了回这里交代一下了。
select ......
intersect
select .....
intersect
select .....搞那么多麻烦干嘛呢?