我的数据库下有有三个用户,三个用户下有有一个表,表结构相同,表名也相同,
我想同时查出三个表的内容,并按其中一个字段排序,就象从一个表查一样因为他们的结构相同.

解决方案 »

  1.   

    SELECT A.COL1 COL1,A.COL2 COL2 FROM A
    UNION SELECT B.COL1 COL1,B.COL2 COL2 FROM B
    UNION SELECT C.COL1 COL1,C.COL2 COL2 FROM C
    ORDER BY COL1
      

  2.   

    SELECT * FROM userA.A
    UNION all SELECT * FROM userB.B
    UNION all SELECT * FROM userC.C
    ORDER BY 1若要去掉重复值,就用不all,但这样速度慢
      

  3.   

    谁懂JSP呢  帮我看看在jsp中的这条语句
    该怎么改
     sql="SELECT a.phonenum x,a.content y,a.createtime z FROM  sms_hd_content a where a.status='0' and substr(a.phonenum,1,7) in (select phone from hd_bm) 
    union select b.phonenum x,b.content y,b.createtime z FROM  mobile.sms_hd_content b where b.status='0' and substr(b.phonenum,1,7) in (select phone from mobile.hd_bm)
    union select c.phonenum x,c.content y,c.createtime z FROM  tele.sms_hd_content c where c.status='0' and substr(c.phonenum,1,4) in (select phone from tele.hd_bm) ORDER BY createtime DESC";