I have multiple tables with same metadata (column names are same). I want to select Latest Records from these table, ordered by CreationDate (such column exist in all tables).

3 Answers
Not sure of the correct syntax in MSSQL, but you should be able to:
SELECT ... FROM table1 UNION table2
(where table1 and table2 have identical columns)
Hope this helps...
2 Comments
marc_s
Welcome to StackOverflow: if you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button (
{ } ) on the editor toolbar to nicely format and syntax highlight it!Maysam
It worked:
SELECT top(3) OwnerID,NewsTitle,NewsCreationDate FROM MoviesNews UNION SELECT top(3) OwnerID,NewsTitle,NewsCreationDate FROM TheaterNews ORDER BY 3 DESCWhy dont you use alias for the tables and select all the columns of both the tables and give the columns different names as per the table names. I think this can help you out.
Thanks, Dipa
1 Comment
dipa
The query can be like SELECT t1.[x] As 'X1',t2.[x] as 'X2' FROM [table1] as t1 INNER JOIN [table2] as t2 On t1.[y] = t2.[y]