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
)
精彩评论