Find rows that have the same values in another column

sqlite

I have the following table.

User Permission
John 1
Mary 1
Anne 1
Joe 2
Marie 2
Nick 3

I want to select and group users with the same permission number. Is this actually possible? I have millions of different permission values.

Expected output:

(John, Mary, Anne), (Joe, Marie), (Nick)

Best Answer

It's probably best to do this in the application, after all it's just presentation. Something like:

SELECT user, permission
FROM T
ORDER BY permission

then keep track of when permission changes.

However (untested), there seems to be a GROUP_CONCAT function that can do what you want:

SELECT GROUP_CONCAT(user), permission
FROM T
GROUP BY permission
ORDER BY permission