15,966,379 members
See more:
Hi,

I have a doubt on SQL Query. I have a multiple columns in that one of the column is "Order" , values are 1,2,3,4,5....

Now, what i want is on every time i want to display 3 is either first or last. How to do this . By using order by ... syntax is possible to do this

Can any one help me to solve this issue..

Posted
fjdiewornncalwe 25-Oct-12 9:42am
Can you give an example of what you want your output to look like? Your question is not clear as it is. Cheers.
joshrduncan2012 25-Oct-12 9:42am
You want to use order by but have the numbers out of order?
[no name] 25-Oct-12 9:49am
THIS IS actual data
1
2
3
4
5....
But i want
1
2
4
5...
3 or

3
1
2
4
5...

## Solution 2

use union all and order by
SQL
```select order from
(
select 1 as tempId, order from tbl where order=3
union all
select 2 as tempId, order from tbl where order<>3
)
as tbltemp
order by tempid,order```

Happy Coding!
:)

damodara naidu betha 31-Oct-12 9:12am
5+
Aarti Meswania 31-Oct-12 9:13am
thank you! :)
damodara naidu betha 31-Oct-12 9:24am
I have posted an answer for the same question .. check it :)

## Solution 1

http://www.w3schools.com/sql/sql_union.asp

## Solution 3

Try this code block.

SQL
```SELECT [ORDER] FROM (
SELECT CASE WHEN [ORDER] = 3 THEN 0 ELSE 1 END ROWNUM,[ORDER] FROM Orders
)A ORDER BY ROWNUM,[ORDER]```

If you want to test this query then please run the following whole code block at once

SQL
```WITH Orders AS
(
SELECT 1 [ORDER]
UNION ALL
SELECT [ORDER] + 1 FROM Orders WHERE [ORDER] < 10
)

SELECT [ORDER] FROM (
SELECT CASE WHEN [ORDER] = 3 THEN 0 ELSE 1 END ROWNUM,[ORDER] FROM Orders
)A ORDER BY ROWNUM,[ORDER]```

Thank you

v3