Delete default order from Union instruction

I want to display such data:

Column1 Column2 ----------------------- TotalAvg 60% A1 50% B1 70% Z1 60% 

My sql script looks something like this:

 select 'Total Avg' as Column1,'60%' as Column2 union select Column1,Column2 from tblAvg 

and the result that I get looks something like this:

 Column1 Column2 ------------------------ A1 50% B1 70% TotalAvg 60% Z1 60% 

Question: I want to delete the default order and get the result in the order in which we make the union tables.

+4
source share
4 answers
 SELECT * FROM ( select 0 as pos, 'Total Avg' as Column1, '60%' as Column2 union select 1 as pos, Column1, Column2 from tblAvg ) AS data ORDER BY pos, column1, column2 
+1
source

You can add a column that sets the order of the result:

 select 'Total Avg' as Column1,'60%' as Column2, 1 as OrderCol union select Column1,Column2, 2 from tblAvg order by OrderCol 

Without order by the database can return rows in any order.

+8
source

You can do something like this

 select * From ( select 'Total Avg' as Column1,'60%' as Column2, 1 as ItemOrder union select Column1,Column2,2 from tblAvg ) innertable Order By ItemOrder 
+1
source

Try using

 select 'Total Avg' as Column1,'60%' as Column2 union all select Column1,Column2 from tblAvg 
0
source

All Articles