If you need to sort the output from two queries grouped together with a UNION operator, you need to apply the ORDER BY clause at the group level, not at the subquery level.
for example: (SELECT * FROM sample WHERE tag = 'MCA' ORDER BY created) UNION (SELECT * FROM sample WHERE tag = 'BCA' ORDER BY created)
Liked By
Write Answer
How To Use ORDER BY with UNION Operators in MS SQL Server?
Join MindStick Community
You have need login or register for voting of answers or question.
Amit Singh
09-Nov-2010for example:
(SELECT * FROM sample WHERE tag = 'MCA' ORDER BY created)
UNION
(SELECT * FROM sample WHERE tag = 'BCA' ORDER BY created)