I'm trying to join two tables with the same structure if they match the primary key of a third table. Then I want to sort based on a column from the 3rd table.
Example structure:
Table 1 - id (VARCHAR) | title (VARCHAR) | expire (TIMESTAMP)
Table 2 - id (VARCHAR) | title (VARCHAR) | expire (TIMESTAMP)
Table 3 - id (VARCHAR) | views (VARCHAR) | expire (TIMESTAMP)
I thought this should work but it doesn't:
SELECT * FROM table1 as t, table3 as t3 WHERE t.id = t3.id
UNION
SELECT * FROM table2 as t2, table3 as t3 WHERE t2.id = t3.id
ORDER BY table3.expire DESC
What could accomplish this?