0

I have these 2 columns in the table and my PHP code on my site is connected to it.

username | primary_group

I currently have it being sorted by username but how would I make it sort by primary_group with the groups in a certain order without making a sort column in the group name table and link the tables?

Currently, I have:

SELECT username, primary_group FROM table_name ORDER BY username.

1 Answer 1

1

You could use MySQL's ORDER BY FIELD capability to specify a certain custom order to use when sorting on primary_group:

SELECT
    username, primary_group
FROM
    table_name
ORDER BY
    FIELD(primary_group, 'group1', 'group2', 'group3', ...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.