简体   繁体   English

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

[英]How to get data from two different table with different columns

table1 表格1

id  | pid   |pdate

1   |ab001  |25/05/2017

2   |ab002  |25/05/2017

table2 表2

id  |rid    |rdate

1   |cd001  |25/05/2017

2   |cd002  |25/05/2017

Output 输出量

id  |cid    |date

1   |ab001  |25/05/2017

2   |ab002  |25/05/2017

1   |cd001  |25/05/2017

2   |cd002  |25/05/2017 
(SELECT table1.id, table1.pid, table1.pdate FROM table1)
UNION
(SELECT table2.id, table2.rid, table2.rdate FROM table2);

Try this example: 试试这个例子:

SELECT id FROM table1 UNION SELECT cid FROM table2;

Output: 输出:

id rid 摆脱

1 ac22 1 ac22

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何 select 特定列并从这些列中获取数据并将它们存储在另一个表的不同列中? (拉拉维尔) - How to select specific columns and get data from those columns and store them in different columns in another table? (Laravel) 如何将两个不同的表中的两列与laravel中的雄辩相乘 - How to multiply two columns from two different table with eloquent in laravel 从名称相同但表不同的两列检索数据 - retrieve data from two columns with the same name but different table 从两个不同的表中获取和联接两个数据,用于If条件PHP - GET AND JOIN two data from two different table for If conditions PHP 如何从CGridView中的不同表中获取数据? - How to get data from different table in CGridView? 如何从PHP中的一个数据库的两个不同表中获取多个数据 - how to get multiple data from two different table from one database in php 比较两个不同表中的两个不同列,并显示laravel 5.2中任一表中其他列的数据 - Compare two different columns from two different tables and show other column's data from either table in laravel 5.2 如何从cakef 2.5中的两个不同的db获取数据但表名相同? - how to get data from two different db but table name is same in cakephp 2.5? 如何从两个不同的表中减去两个不同的列的值? - How to subtract values of two different columns from two different tables? 如何从不同列中的单独表中获取数据而不重复 - how to get data from separate tables in different columns with no repetition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM