i have the following query
SELECT DISTINCT dr.Revision
FROM tblActionHeader ah
INNER JOIN tblActionType at ON at.ActionTypeID = ah.ActionTypeID
INNER JOIN tblDocumentRevisionActionHeader drah ON drah.ActionHeaderID = ah.ActionHeaderID
INNER JOIN tblDocumentRevision dr on dr.DocumentRevisionID = drah.DocumentRevisionID
INNER JOIN tblDocumentHeader dh on dh.DocumentHeaderID = dr.DocumentHeaderID
WHERE at.ActionTypeID=2
UNION SELECT '(All)'
FROM tblActionHeader ah
it returns the following result set
-
(All)
0
0a
1
i need ‘(All)’ to take at the top of the result set how can i do this?
Two ways – first would be to put the “All” at the top of the UNION:
The second is to assign an arbitrary value for ordering by:
I used the derived table approach in this example to make sure that only the
revisioncolumn is in the final result set.Use
UNION ALLif you know the values will be distinct/unique —UNIONremoves duplicates, and is slower for that reason.