0

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?

parboy
  • 67
  • 8

2 Answers2

2

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612
0
    SELECT meetID, meetingTitle FROM  meetings
    ORDER BY 
    CASE WHEN meetingTitle = 'Other Meetings' THEN 2 ELSE 1 END, meetingTitle DESC
Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236