How to arrange mysql query result according to where conditions ?
I am running query like
$query = "SELECT * FROM students WHERE name = ahmed or age > 20";
the result will be any person has name ahmed or greater than 20 years
I want the name result get first ( all students have this name 'ahmed' ) not the age .
How can i do this ?
Order by name='ahmed' descending:
$query = "SELECT * FROM students WHERE name = ahmed or age > 20 ORDER BY name = 'ahmed' DESC";
You are ordering on the truthiness of the expression; the name='ahmed' will evaluate as either true or false (1 or 0).
Please or to participate in this conversation.