大家帮忙来个两表联合查询:
表A
sheng shi
吉林 长春
吉林 四平
吉林 白城
辽宁 鞍山
辽宁 四平表B
sheng shi
吉林 长春
吉林 长春
吉林 长春
吉林 四平
吉林 四平表A里面没有重复的记录,表B里面有重复的,我想找出的结果为:
sheng shi
吉林 白城
辽宁 鞍山
辽宁 四平假如吉林和辽宁都有四平这个市,
该怎么联合查询呢?大家帮忙下,弄了很久就是不好使。
只要好使立马给分
表A
sheng shi
吉林 长春
吉林 四平
吉林 白城
辽宁 鞍山
辽宁 四平表B
sheng shi
吉林 长春
吉林 长春
吉林 长春
吉林 四平
吉林 四平表A里面没有重复的记录,表B里面有重复的,我想找出的结果为:
sheng shi
吉林 白城
辽宁 鞍山
辽宁 四平假如吉林和辽宁都有四平这个市,
该怎么联合查询呢?大家帮忙下,弄了很久就是不好使。
只要好使立马给分
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
)
合并字段不能用“_”来连接,是用concat(sheng,shi)来合并字段。select * from A where concat(sheng,shi) not in(select distinct concat(sheng,shi) from B);