簡單點說
表一:
name1里面有 1 2 
表二:
name2里面有 1 3 
表三:
name3里面有 3 4
請問各位高手 我現在想查詢的結果顯示為 1 2 3 4 。這查詢語句如何實現??

解决方案 »

  1.   

    SELECT * 
    FROM ta AS b
    UNION SELECT * 
    FROM tb
    UNION SELECT * 
    FROM tc
    LIMIT 0 , 30
      

  2.   

    SELECT * FROM ta UNION SELECT * FROM tb UNION SELECT * FROM tc
      

  3.   


    create table tb1 (name1 int);
    create table tb2 (name2 int);
    create table tb3 (name3 int);
    insert into tb1 values (1),(2);
    insert into tb2 values (1),(3);
    insert into tb3 values (3),(4);select * from tb1;
    select * from tb2;
    select * from tb3;select name1 as name from tb1
    union
    select name2 as name from tb2
    union
    select name3 as name from tb3
    ;drop table tb1,tb2,tb3;
      

  4.   


    mysql> select name1 from `table`;
    +-------+
    | name1 |
    +-------+
    | 1     |
    | 4     |
    +-------+
    2 rows in set (0.00 sec)mysql> select name2 from `table2`;
    +-------+
    | name2 |
    +-------+
    | 1     |
    | 5     |
    +-------+
    2 rows in set (0.00 sec)mysql> select name3 from `table3`;
    +-------+
    | name3 |
    +-------+
    | 3     |
    | 6     |
    +-------+
    2 rows in set (0.02 sec)mysql> select name1 name from `table` union select name2 name from table2 union
    select name3 name from table3 order by name;
    +------+
    | name |
    +------+
    | 1    |
    | 3    |
    | 4    |
    | 5    |
    | 6    |
    +------+
    5 rows in set (0.00 sec)
    ...和楼上的一样了。既然写了就发一下拉。