In my ASP.NET application, I am wishing to select top 20 records (10 and 10) from two different tables named 'PostedByAdmins' and 'PostedByGuest'. I have used following queries but no use:-
SELECT TOP 20 [title], [source], [description] FROM [PostedByAdmins, PostedByGuest] ORDER BY [id] DESC
SELECT TOP 20 [title], [source], [description] FROM [PostedByAdmins], [PostedByGuest] ORDER BY [id] DESC
Even I tried to delete TOP 20 even I don't wish this but no use like
SELECT [title], [source], [description] FROM [PostedByAdmins], [PostedByGuest] ORDER BY [id] DESC
I tried to delete TOP 20 and ORDER by but no use as
SELECT [title], [source], [description] FROM [PostedByAdmins], [PostedByGuest]
For the demonstration purpose I check both table one by one and this worked fine
SELECT TOP 20 [title], [source], [description] FROM [PostedByAdmins] ORDER BY [id] DESC
SELECT TOP 20 [title], [source], [description] FROM [PostedByGuest] ORDER BY [id] DESC
So, there is no problem with development of tables or say in other coding except query.
So, guys what query I use to fix my issue. Remeber I need top 10 records from both tables.
Thanks in advance.
Loading

Guest UserPosted Apr 28, 2011, 1:48 PM
If the idea is to merge the two top-10 lists together then you need to use a UNION clause such as in this untested example ;)
SELECT * FROM
(SELECT TOP 10 [id], [title], [source], [description] FROM [PostedByAdmins] ORDER BY [id] DESC
UNION
SELECT TOP 10 [id], [title], [source], [description] FROM [PostedByGuest] ORDER BY [id] DESC) AS merged
ORDER BY [id] DESC