I have a SQL problem which seem simple but I can't find the solution...
My table structure is as follows:
+----+----------------------+---------------+------------------+
| id | username | primary_group | secondary_groups |
+----+----------------------+---------------+------------------+
| 1 | Username1 | 3 | 7,10 |
| 2 | Username2 | 7 | 3,5,10 |
| 3 | LongUsername | 1 | 3,7 |
+----+----------------------+---------------+------------------+
I am trying to display users which are in Group 7 (either primary or secondary) groups.
My current SQL query is as follows:
SELECT * FROM users WHERE primary_group = 7 OR secondary_groups IN (7)
The issue I'm facing is the query above only displays the following output.
+----+----------------------+---------------+------------------+
| id | username | primary_group | secondary_groups |
+----+----------------------+---------------+------------------+
| 1 | Username1 | 3 | 7,10 |
| 2 | Username2 | 7 | 3,5,10 |
+----+----------------------+---------------+------------------+
How would I display LongUsername in the list (my query doesn't work if there is a secondary_group before 7 (e.g. secondary_groups 3,6,7)
Any help/suggestions?