Reputation: 69259
Consider I have the following two tables (rough sketches):
Table 1:
Table 2:
Suppose I want to select results from both tables and order them by time
, is this doable? I myself was thinking it would be possible, if:
time
being shared over the union.NULL
values in places where this is no match. For example a row of Table 1 in this union would have NULL
in t2Id, attribute4 and attribute5.NULL
values) originated from.How would I design such a query in the most efficient way?
Upvotes: 0
Views: 123
Reputation: 702
SELECT * FROM (
SELECT t1Id,time , attribute1,attribute2,attribute3 FROM table1
UNION ALL
SELECT t2Id ,time , attribute3,attribute4,"" FROM table2
)AA
ORDER BY AA.time
Upvotes: 1