Sort values in MySQL using HAVING clause and IN function I have this portion of code with user's phone extensions:

GROUP BY IFNULL(mxuser.EXTENSION, mxuser_1.EXTENSION)
HAVING Ext IN (207, 213, 235, 214, 226, 218, 224, 227, 216)


It works fine, and it sorts values in ASC order ( 207, 213, 214..) Is it possible to sort values in different order? Something like this:

( 235, 207, 218 .. )
I'm not sure why you're putting the EXT IN a HAVING clause, but this should work.

WHERE IFNULL(mxuser.EXTENSION, mxuser_1.EXTENSION)
  IN (207, 213, 235, 214, 226, 218, 224, 227, 216)
GROUP BY IFNULL(mxuser.EXTENSION, mxuser_1.EXTENSION)
ORDER BY ext=235 DESC, ext=207 DESC, ext=218 DESC, ext;