Reputation: 67
I can make a selected record appear at the beginning of a sorted query:
$sql = "SELECT meetID, meetingTitle
FROM meetings
ORDER BY meetingTitle = 'Other Meetings' DESC, meetingTitle DESC";
That forces "Other Meetings" to be at the top of an alphabetical array output. I want it to be at the bottom. I can then use array_reverse to place it at the end of the output array, but I am looking for a direct approach with the MySQL query. Is that possible?
Upvotes: 0
Views: 25
Reputation: 780843
Change ASC
to DESC
:
$sql = "SELECT meetID, meetingTitle
FROM meetings
ORDER BY meetingTitle = 'Other Meetings' ASC, meetingTitle DESC";
The value of meetingTitle = 'Other Meetings'
is 1
for Other Meetings
and 0
for other values. So if you want other values first, you want 0
to be ahead of 1
, and that's ASCending order.
Upvotes: 2
Reputation: 42753
SELECT meetID, meetingTitle FROM meetings
ORDER BY
CASE WHEN meetingTitle = 'Other Meetings' THEN 2 ELSE 1 END, meetingTitle DESC
Upvotes: 0