'MYSQL rotate a returned data
I'm getting a data that return like this:
| id | name |
| 1 | customer1 |
| 2 | customer2 |
| 3 | customer3 |
| 4 | customer4 |
Now I want to rotate it so it return like this:
| id | name |
| 3 | customer3 |
| 4 | customer4 |
| 1 | customer1 |
| 2 | customer2 |
How can i Achieve it in MYSQL?
Solution 1:[1]
OK. If you need to sort it like 4, 5, 6, 1, 2, 3
Use this query:
SELECT id, name FROM customers
ORDER BY id >= 4 DESC, id;
Solution 2:[2]
i think this code you need
SELECT * FROM Customers
ORDER BY id ASC;
replace
ASC
byDESC
for get id descending
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ayman Doukkali |