Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
//my union first query
select b.UserId,b.UserName from Users b where b.UserId='e47277ab-5c62-4311-80f9-b5705fd075f6'

union
//my union secode query
select a.userId,a.UserName + '-' + a.FirstName + a.LastName As UserName from Users a
where a.ParentUserId='e47277ab-5c62-4311-80f9-b5705fd075f6'


When i run these query i want to get FirstQuery Data come first and Secode Query Data come after First query. data. do u have any solution for that.
Posted

1 solution

Hi,

Something like this should help.

... the SQL is untested, but it should get you most of the way there.


SQL
SELECT 
 t.UserId
,t.UserName
FROM
(
--my union first query
select 1 AS OrderColumn, b.UserId,b.UserName from Users b where b.UserId='e47277ab-5c62-4311-80f9-b5705fd075f6'
union
--my union secode query
select 2 AS OrderColumn, a.userId,a.UserName + '-' + a.FirstName + a.LastName As UserName from Users a
where a.ParentUserId='e47277ab-5c62-4311-80f9-b5705fd075f6'
) AS t
ORDER BY
t.OrderColumn
; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900