views:

75

answers:

2

MySQL:

id | name  |
------------
1  | Joe   |
2  | Craig |
3  | Shawn |
4  | Ryan  |
5  | Seth  |

PHP:

$a = mysql_query("SELECT * FROM table_name ORDER BY name DESC");

what I want to do though is, I want to start at id: 3, so it should output:

3,4,5,1,2

+5  A: 

EDIT : Mark is correct. The earlier query was syntactically incorrect. Using dummy aliasés should work!

Select id from
(
    SELECT id FROM table_name 
    WHERE id >= 3 
    ORDER BY id ASC
) X   

UNION

Select * from
(
    SELECT id FROM table_name 
    WHERE id < 3 
    ORDER BY id ASC
) Y

This should give you 3,4,5,1,2

InSane
+3  A: 

You can use an expression in the ORDER BY:

SELECT id, name
FROM table_name
ORDER BY id < 3, id

Result:

3  Shawn
4  Ryan
5  Seth
1  Joe
2  Craig

I'd also advise you not to use SELECT * and instead to list the columns explicitly.

Mark Byers
+1 - This is a much cleaner way of achieving the same thing!! :-)
InSane