January 3, 2012 at 3:48 pm
Hi All,
I have a question about the defualt order of values in the result set when using "Union ALL" between two tables.In the example below,
will the table1 values always appear first in the final result set followed by the values from table2?
Please refer to the example the exmaple below:
Select employee,employeename from table1
union all
Select employee,employeename from table2
The reason I am asking this is, in my ssrs report I always want to display the employeename
from table1 in the group header which is grouped by employeeid.
January 3, 2012 at 6:41 pm
There is no default order to any result set, unless you have an ORDER BY clause.
January 4, 2012 at 5:08 am
Sort order must be explicitly defined in the ORDER BY clause.
One way to accomplish what you're after could be this:
SELECT *
FROM (
Select 'table1' as SRC, employee,employeename from table1
union all
Select 'table2' as SRC, employee,employeename from table2
) AS data
ORDER BY SRC, employee, employeename
Hope this helps
Gianluca
-- Gianluca Sartori
January 4, 2012 at 5:45 am
Ok, so why not just use the order by in SSRS??
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply