SELECT u.nick, u.realname, u.connecttime, u.away, u.awaymsg, i.mode_lh, i.mode_lo, i.mode_lv FROM (user u LEFT JOIN (ison i LEFT JOIN chan c ON i.chanid=c.chanid) ON u.nickid=i.nickid) WHERE channel='#test' ORDER BY i.mode_lo ASC, i.mode_lh ASC, i.mode_lv ASC, u.connecttime ASC