初学者,向大侠们请教一个sql语句如何写,描述如下:
有三个表tab1,tab2,tab3.  
三个表中都有code(代码)和date(日期)这两列,
其中code是关键字,
现在我想选出三个表中code字段相同时所有不重复的date数据,按照从大到小的顺序输出,
请教一下该如何写这个sql语句啊 

解决方案 »

  1.   

    select code,date from tab1
    union
    select code,date from tab2
    union
    select code,date from tab3 order by code,date
      

  2.   

    select distinct * from 
    (
    select code,date from tab1
    union
    select code,date from tab2
    union
    select code,date from tab3 order by code,date
    )t
      

  3.   

    select distinct * from 
    (
    select code,date from tab1
    union all
    select code,date from tab2
    union all
    select code,date from tab3 )t
    order by code,date
      

  4.   

    select code,date from tab1
    union all
    select code,date from tab2
    union all
    select code,date from tab3 order by code,date
      

  5.   

    select code,date from tab1
    union all
    select code,date from tab2
    union all
    select code,date from tab3 
    order by code,date
      

  6.   

    兄弟,你测试过没,如果是两个查询直接 union,就会直接过滤掉重复值,3楼把重复值先全查到,再来个distinct过滤,恐怕不是很好的办法吧!
      

  7.   

    哦, 是啊! 这个...sorry 我不熟悉这个, 所以就....