请问!!!如何从两个表中查出两个相同字段中的相同值??

比如有两个表A,B中都有xm(即姓名)字段,怎样查出两个表中有相同姓名的两个人呢?带着其它字段一起显示。我在一个表中可以实现,就是用having 过滤。可是两个表怎么办?
---------------------------------------------------------------

SELECT *
FROM A FULL OUTER JOIN B
ON A.xm=B.xm
或者
SELECT *
FROM A FULL OUTER JOIN B
USING(xm)
或者
SELECT *
FROM A NATUREL FULL OUTER JOIN B

---------------------------------------------------------------

select a.xm,a.filed1,b.field1 from a,b
where a.xm=b.xm
---------------------------------------------------------------

select A.,B. from a,b
where a.xm=b.xm

---------------------------------------------------------------

什么意思。你在一个表中能实现,那两个都实现后放到临时表里再关联不行吗?是想一句写出来吗?那可以试试嵌套子查询。
---------------------------------------------------------------

就只有嵌套满足你的要求了!

---------------------------------------------------------------

表A:
select * from a
where xm in (
select xm from (
select xm from a
union all
select xm from b
) as c
having count(xm)>1
)

表B:
select * from b
where xm in (
select xm from (
select xm from a
union all
select xm from b
) as c

having count(xm)>1
)

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus