举个列子,
table1 有A,B,C三列
假设数据有
A             B           C
A001   B001    C001
A002   B002    C001    
A003   B003    C001table2 有   A,B,C,D,E假设数据有A             B           C                D               E
A001    B001    C001           ...              ..
A002    B002    C001           ...              ..
A004    B004    C001           ...              ..
问题: 我想查出两份表中C列=‘C001’的 A,B两列的数据,去除重复的数据。

解决方案 »

  1.   

    select a,b from table1 where c='C001' union 
    select a,b from table2 where c='C001'
    是想问Union 和union all的区别吧?
      

  2.   

    方法一:
    select A,B from table1 where C='C001' 
    union 
    select A,B from table2 where C='C001'方法二:
    select 
    distinct       -- 去除重复项
    *
    from(
    select A,B from table1 where C='C001' 
    union all
    select A,B from table2 where C='C001')