在SQL語句中可以使用Union查找兩個表的并集.

解决方案 »

  1.   

    select * 
    from tableA
    union 
    select *
    from tableB
      

  2.   

    问这样得到的表能放在from后吗?
    比如:
    Select ...from (SELECT a FROM table_name WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
    UNION
    (SELECT a FROM table_name WHERE a=11 AND B=2 ORDER BY a LIMIT 10)
    ORDER BY a
      

  3.   

    啊?!
    可是我想从这个union生成的表中查找啊!!
      

  4.   

    select * from tableA,tableB where tableA.id=1 or tableB.id=1
    不知道mysql能用否?
      

  5.   

    tableA结构:   id, name, age, sex, citytableB结构:   id, name, ageSelect id, name, age, sex, city From tabelA Where id=1 Union Select id, name, age, '' as sex, '' as city From tableB Where id=1
      

  6.   

    如果在两个表使用UNION  就要让它们被查询出来的字段个数,字段名都相同
      

  7.   

    如果你的两个表的字段名都是如A1,A2,A3,A4,A5,......思路可能会清晰一些,这样用UNION可能会方便,具体你要自己试试。
      

  8.   

    select a.* , b.* from 表a a,表b b where a.id=b.id
      

  9.   

    SELECT type,score FROM table_name1 UNION SELECT type,score FROM table_name2