skiwi
skiwi

Reputation: 69259

MySQL order by time on two different tables

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:

How would I design such a query in the most efficient way?

Upvotes: 0

Views: 123

Answers (1)

Agoeng Liu
Agoeng Liu

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

Related Questions