0

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). Something like this

3 Answers 3

2

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...

Sign up to request clarification or add additional context in comments.

2 Comments

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!
It worked: SELECT top(3) OwnerID,NewsTitle,NewsCreationDate FROM MoviesNews UNION SELECT top(3) OwnerID,NewsTitle,NewsCreationDate FROM TheaterNews ORDER BY 3 DESC
1
SELECT newTable.MyData, newTable.CreationDate FROM
(SELECT MyData, CreationDate FROM Table1
UNION
SELECT MyData, CreationDate FROM Table2) AS newTable
ORDER BY newTable.CreationDate DESC

Comments

1

Why 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

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.