如何从具有不同列的两个不同表中获取数据

时间:2017-05-25 07:30:05

标签: php mysqli

表1

id  | pid   |pdate

1   |ab001  |25/05/2017

2   |ab002  |25/05/2017

表2

id  |rid    |rdate

1   |cd001  |25/05/2017

2   |cd002  |25/05/2017

输出

id  |cid    |date

1   |ab001  |25/05/2017

2   |ab002  |25/05/2017

1   |cd001  |25/05/2017

2   |cd002  |25/05/2017 

2 个答案:

答案 0 :(得分:1)

(SELECT table1.id, table1.pid, table1.pdate FROM table1)
UNION
(SELECT table2.id, table2.rid, table2.rdate FROM table2);

答案 1 :(得分:0)

试试这个例子:

SELECT id FROM table1 UNION SELECT cid FROM table2;

<强>输出:

id rid

1 ac22