SELECT TOP 100 PERCENT *
FROM (SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
2 AS folderType, hasattachment, uid
FROM jmOutbox
WHERE istrash = 1
UNION
SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
1 AS folderType, hasattachment, uid
FROM jmInbox
WHERE istrash = 1
UNION
SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
3 AS folderType, hasattachment, uid
FROM jmDraftbox
WHERE istrash = 1 ) temptable
ORDER BY senttime DESC
FROM (SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
2 AS folderType, hasattachment, uid
FROM jmOutbox
WHERE istrash = 1
UNION
SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
1 AS folderType, hasattachment, uid
FROM jmInbox
WHERE istrash = 1
UNION
SELECT indexid, sentfrom, subject, senttime, msgsize, username, istrash,
3 AS folderType, hasattachment, uid
FROM jmDraftbox
WHERE istrash = 1 ) temptable
ORDER BY senttime DESC