Ramin
Ramin

Reputation: 483

mysql result from WHERE and the rest

assume that I have a table like this

table name = myTable
id  
----
1
2
3
4
5
6
7

is there any way to fetch some rows with this query

SELECT * FROM `myTable` WHERE id IN (1,5,7) OR ... ;

and in fill the ... with any thing that give me the result for WHERE clause first, and the rest of the rows after those rows??? somethig like this:

1,5,7,2,3,4,6

Upvotes: 0

Views: 35

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269483

You don't do this with a where, you do this with an order by. Like this:

order by (id in (1, 5, 7)) desc

MySQL interprets boolean values as integers, with 0 being false and 1 being true. The desc will put the true values before the false ones.

Upvotes: 3

Related Questions