Answer the question
In order to leave comments, you need to log in
How to sort a query using UNION?
SELECT TOP 50 id, fid, uid, type, val, message FROM sw.dbo.logs WHERE [email protected] or ([email protected] and type=100) ORDER BY id DESC;
SELECT TOP 50 id, fid, uid, type, val, message FROM sw.dbo.logs WHERE [email protected] ORDER BY id DESC;
SELECT TOP 50 id, fid, uid, type, val, message FROM sw.dbo.logs WHERE ([email protected] and type=100) ORDER BY id DESC;
(SELECT TOP 50 id, fid, uid, type, val, message FROM sw.dbo.logs WHERE [email protected] ORDER BY id DESC)
UNION ALL
(SELECT TOP 50 id, fid, uid, type, val, message FROM sw.dbo.logs WHERE ([email protected] and type=100) ORDER BY id DESC) ORDER BY id DESC;
Answer the question
In order to leave comments, you need to log in
SELECT * FROM (...your query...) ORDER BY desired_field.
Just do not know how with the performance in this case.
I'll ask just in case: is your indexing configured for your needs?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question