Satch3000
Satch3000

Reputation: 49404

PHP SQL Condition on ORDER BY

I am trying to display all records with field_featured = 1 to start at the top of my listing ... and all the others to display at RAND()

So...

SELECT * FROM myTable

If (field_featured = 1 then ORDER BY field_featured) OTHERWISE (ORDER BY RAND() )

How can I do this?

Upvotes: 1

Views: 61

Answers (1)

Karo
Karo

Reputation: 744

Try this:

ORDER BY (field_fieatured=1) DESC, RAND()

Upvotes: 4

Related Questions