0
I have a query that selects all group members in rank order (owner, administrator and member) and by the date when the member joined the group. By the column access_level
not being numerical I don’t know how I put in rank order.
SELECT * FROM group_memberships WHERE group_id = ? ORDER BY access_level ASC, STR_TO_DATE(date_joined, '%M %Y') ASC LIMIT;
access_level uses ENUM data type Owner, Administrator and Member, and it’s exactly in this order that I want.
How can I do this?
Use the function
FIELD
. Ex:SELECT * FROM table ORDER BY FIELD(access_level, 'owner', 'adm', 'member')
– Valdeir Psr