t1表:
country area
a 11
e 22
f 33
g 44t2表:
country area
a 1
b 2
c 3
d 4
我现在要把两表的信息组合起来,相同的国家只显示一条记录(也就是屏蔽另一条记录),应当如何控制他显示哪一个表的内容?

解决方案 »

  1.   

    select * 
    from t1
    union all
    select * 
    from t2 a
    where not exists(select 1 from t1 where country = a.country)
      

  2.   

    select country ,max(area ) as area 
    from (
        select * from t1
        unoion all
        select * from t2) b
    group by b.country 
      

  3.   

    我想出来了
    select * from t1
    union all
    select * from t2 where country not in (select country from t1)