Chris
Chris

Reputation: 67

MySQL order INT but 0 goes last

Can I perform a query to order by an INT in ASC order but put any records with 0 last?

e.g.

1, 2, 3, 4, 6, 100, 0

Rather than

0, 1, 2, 3, 4, 6, 100

Upvotes: 2

Views: 1119

Answers (2)

Nicola Cossu
Nicola Cossu

Reputation: 56367

select * from table order by if(your_field=0,1,0),your_field

Upvotes: 1

Emmerman
Emmerman

Reputation: 2343

SELECT IF(row>0, row, 100000) as sort_row ...... ORDER BY sort_row ASC

OR use UNION

Upvotes: 0

Related Questions