SELECT * FROM ta AS b UNION SELECT * FROM tb UNION SELECT * FROM tc LIMIT 0 , 30
SELECT * FROM ta UNION SELECT * FROM tb UNION SELECT * FROM tc
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;
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) ...和楼上的一样了。既然写了就发一下拉。
FROM ta AS b
UNION SELECT *
FROM tb
UNION SELECT *
FROM tc
LIMIT 0 , 30
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;
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)
...和楼上的一样了。既然写了就发一下拉。