日期:2014-05-16  浏览次数:20859 次

简单的联合查询,只要写对,立马给分。在线,要分的速度。
大家帮忙来个两表联合查询:
表A
sheng       shi
吉林         长春
吉林         四平
吉林         白城
辽宁         鞍山
辽宁         四平

表B
sheng       shi
吉林         长春
吉林         长春
吉林         长春
吉林         四平
吉林         四平

表A里面没有重复的记录,表B里面有重复的,我想找出的结果为:
sheng       shi
吉林         白城
辽宁         鞍山
辽宁         四平

假如吉林和辽宁都有四平这个市,
该怎么联合查询呢?大家帮忙下,弄了很久就是不好使。
只要好使立马给分

------解决方案--------------------
你要是市好像没什么规律啊
------解决方案--------------------
select * from chengshi
where id not in (
select a.id from chengshi a,chengshi_bak b
where a.sheng = b.sheng and a.shi = b.shi
group by a.id)
------解决方案--------------------

try this:

select * from tabA
where sheng+ '_ '+shi not in
(
select sheng+ '_ '+shi from tabB
group by sheng, shi
)