Thursday, April 19, 2012

Brain boiling from MySQL - How to do a complicated select from multiple tables?

I have two tables: Users and Groups



In my table "Users", there is a column called "ID" for all the user ids.



In my table "Groups" there is a column called "Participants", fields in this column are filled with all the user ids like this "PID_134,PID_489,PID_4784," - And there is a column "ID" that identifies a specific group.



Now what i want to do, i want to create a menu that shows all the users that are not yet in this particular group.



So i need to get all the user ids, that are not yet in the Participants column of a group with a particular ID.



It would be cool if there was a single mysql query for that - But any PHP + MySQL solutions are okay, too.



How does that work? Any guesses?



UPDATE:

i know, that's not code, but is there a way I could do something like this that would return me a list of all the users?



SELECT * 
FROM users, groups
WHERE groups.participants NOT LIKE '%PID_'users.id'%' AND groups.id = 1;




No comments:

Post a Comment