UNION ALL And Order BY
Dear
Friends
I
have come across feature in SQL server which is less known to developers. Union
ALL and Order by together. Fill combo box with union of two tables and order by Ascending. I
would normally write it as
SQL
:-
Select PersonName From
(
Select PersonName
From TranPersonDetails
Union All
Select CompanyName
From TranCompanyDetails
) AllData
Order by PersonName
Look into above SQL :-
Additonal Select statment on top
to add order by. Found easier way to
provide order without Top Select Statement
SQL :-
Select PersonName From TranPersonDetails
Union
All
Select CompanyName From
TranCompanyDetails
Order By
PersonName
No need to have additonal
Select Statment.Order by will work for
both queries,
This even works with SQL SERVER 2000.
Comments
Post a Comment