AsishRaj
asked on
Select Top * From table
Hello experts
i am creating a latest news section on my clients website.
I want to show 5 news details on each section. i have four sections in total thus needing 20 news title.
getting the top 5 is okay.
for the second section, i am using this query to get the details.
SELECT TOP 5 ID, NewsTitle, DocumentName, UploadDate FROM (SELECT TOP 5 ID, NewsTitle, DocumentName, UploadDate FROM (SELECT TOP 10 ID, NewsTitle, DocumentName, UploadDate FROM News ORDER BY UploadDate DESC) AS X ORDER BY UploadDate) AS Y ORDER BY UploadDate DESC
Now lets assume, that there is only 5 news details entered in the datable. this query will retrieve me the same 5 new details as with :
SELECT TOP 5 NewsTitle, DocumentName, UploadDate FROM _News ORDER BY UploadDate DESC
How can i avoid getting the same content on the both section. Initally when the website goes live there will be one or two news details entered. hence i need to cater for the above scenario as well.
Appreciate your help.
i am creating a latest news section on my clients website.
I want to show 5 news details on each section. i have four sections in total thus needing 20 news title.
getting the top 5 is okay.
for the second section, i am using this query to get the details.
SELECT TOP 5 ID, NewsTitle, DocumentName, UploadDate FROM (SELECT TOP 5 ID, NewsTitle, DocumentName, UploadDate FROM (SELECT TOP 10 ID, NewsTitle, DocumentName, UploadDate FROM News ORDER BY UploadDate DESC) AS X ORDER BY UploadDate) AS Y ORDER BY UploadDate DESC
Now lets assume, that there is only 5 news details entered in the datable. this query will retrieve me the same 5 new details as with :
SELECT TOP 5 NewsTitle, DocumentName, UploadDate FROM _News ORDER BY UploadDate DESC
How can i avoid getting the same content on the both section. Initally when the website goes live there will be one or two news details entered. hence i need to cater for the above scenario as well.
Appreciate your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you need the ID or any other fields returned, just include it in both select statements.
i.e.
SELECT ID, News...
FROM
(SELECT ID, News...
...
i.e.
SELECT ID, News...
FROM
(SELECT ID, News...
...
ASKER
that worked.
Open in new window