Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Table like this

id  name col1
1   a    2
2   b    1
3   c    1
4   d    0
5   e    0
6   f    3
7   g    3

And i want output like this where 
1st i want my list in ASC oreder except "0"
and at the end i want to merge the all row that contains "0"

name col1
b    1
c    1
a    2
f    3
g    3
d    0
e    0
Posted

1 solution

think of it as two queries first

SQL
select name, col1 from table where col1 != 0 order by name

and

SQL
select name, col1 from table where col1 = 0 order by name


now, if you think of my 'and' as a 'union' you should know what to do to put the two queries together (you may need to modify my SQL slightly, Im not sure if for example != is valid in your SQL platform, but you should get the idea)

give it a shot, play around - the only way you learn is by doing, maybe getting it wrong, but then trying again
 
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