Do this

SELECT *, 1 as SortOrder
FROM Table1

UNION

SELECT *, 2 as SortOrder
FROM Table2

ORDER BY SortOrder

and it will put query 1 records before query 2 records, which is what I
think you're after from the text.

HTH,

Sam

-----Original Message-----
From: George Abraham [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 09, 2004 11:56 AM
To: CF-Talk
Subject: union and sorting

Hi all,
SQL Server question. I have a query like so:
*******
SELECT *
FROM Table1
WHERE Table1Item  = 'something'

UNION

SELECT *
FROM Table2
WHERE Table2Item = 'something'

********

SQL Server does not allow me to put in individual 'ORDER BY' statements on
the individual selects.

*******
SELECT *
FROM Table1
WHERE Table1Item  = 'something'
ORDER By SomeTableColumn

UNION

SELECT *
FROM Table2
WHERE Table2Item = 'something'
ORDER By SomeTableColumn

********

Instead I can only put an 'ORDER BY' statement at the end of all the
unions. I can't have that. I need to be able to show the results from the
first select first, then the results from the second select.

Any soultions?

Thanks,
George
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to