开发者

Select same column for 2 tables

开发者 https://www.devze.com 2023-03-20 21:01 出处:网络
I have 2 basic tables : Table1 id1 | lastModif_date 110/10/10 210/10/10 310/10/10 and Table2 id2 | lastModif_date

I have 2 basic tables :

Table1
id1 | lastModif_date
1     10/10/10 
2     10/10/10
3     10/10/10

and

Table2
id2 | lastModif_date
1     11/02/11 
2     11/02/11

I'd like to have a select qu开发者_如何学编程ery that return

id1  | id2  | lastModif_date
1      null   10/10/10
2      null   10/10/10
3      null   10/10/10
null   1      11/02/11
null   2      11/02/11

This must be really easy to do, but I can't catch it ...


select table1.id1, null as id2, table1.lastModif_date from table1
union all
select null, table2.id2, table2.lastModif_date from table2


SELECT ID1, NULL AS ID2, lastModif_Date
FROM Table1
UNION
SELECT NULL AS ID1, ID2, lastModif_Date
FROM Table2


SELECT id1, NULL AS id2, lastModif_date FROM Table1
UNION ALL
SELECT NULL as id1, id2, lastModif_date FROM Table2


You need to have join query and make alias of the table and then u can access...

select id1, id2, lastModif_date
from
(
select * from table1

union all

select * from table2
)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号