I want to pull all records except the TOP 10 in my statement but I keep running into problems when using ORDER BY in my subquery “Incorrect Syntax near the keyword ORDER”
@ID INT
as
SELECT ComVID, VID, MID, Ucomment, UdateAdded, MemberId, UserName, Avatar
FROM table.miComments JOIN table.mbrProfile2 ON MID = MemberId
WHERE VID = @ID EXCEPT (SELECT ComVID, VID, MID, Ucomment, UdateAdded, MemberId, UserName, Avatar FROM table.miComments JOIN table.mbrProfile2 ON MID = MemberId
WHERE VID = @ID ORDER BY UdateAdded DESC) 'ERROR: Incorrect Syntax near the keyword ORDER'
ORDER BY UdateAdded DESC
If you’re using MS SQL Server, there is no LIMIT or OFFSET equivalent, so you’d have to use a subquery to accomplish what you want.
The following StackOverflow link has a lot more information in it, which may be helpful:
LIMIT 10..20 in SQL Server