(SELECT Name FROM Employee Group By Name) UNION (SELECT Name FROM Consultant Group By Name) ORDER BY Name;
Do you expect the same Name in multiple rows in these tables? If not, you can drop the GROUP BY Name as well:
(SELECT Name FROM Employee) UNION (SELECT Name From Consultant) ORDER BY Name;
If, on the other hand, Name is not unique, I'd suggest using DISTINCT instead of GROUP BY (just because it more accurately reflects what you want):
(SELECT DISTINCT Name FROM Employee UNION (SELECT DISTINCT Name FROM Consultant) ORDER BY Name;
Of course, if this was just an example and your real query includes an aggregate function, keep the GROUP BY.
Michael
Ed Reed wrote:
Thanks Jeremy,
That was easy.
- Ed
Jeremy March <[EMAIL PROTECTED]> 3/12/04 7:42:12 PM >>>
Can anyone tell me how to sort the combined results of a Union
query?
(Select Name From Employee Group By Name Order By Name) Union (Select Name From Consultant Group By Name Order By Name);
Just add another order by on the end after the parenthesis:
(Select Name From Employee Group By Name Order By Name) Union (Select Name From Consultant Group By Name Order By Name) ORDER BY Name;
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]