Reputation: 14780
How can I make this query to SELECT
from 4 different tables and return the results ordered by date across all 4 tables ? (I need the latest 200 results ordered by date)
SELECT *
FROM [CPU_Benchmarks]
JOIN [CPU_Slugs] ON CPU_Benchmarks.Id = CPU_Slugs.BenchmarkId AND [Approved] = 'true'
ORDER BY [TimeStamp] DESC
The tables are very similar
Upvotes: 2
Views: 577
Reputation: 44605
depending on what exactly you are trying to do, the UNION statement could help, for example:
SELECT TOP 200 col1, col2
FROM
(
SELECT col1, col2 FROM table1
UNION
SELECT col1, col2 FROM table2
UNION
SELECT col1, col2 FROM table3
UNION
SELECT col1, col2 FROM table4
) myTableAlias
ORDER BY col1
you can of course enrich this with your joins or other required logic.
Upvotes: 4