SELECT `groups`.`name`, `groups`.`id`
FROM `groups`
JOIN `group_members`
ON (`group_members`.`user_id` = `groups`.`user_id`)
WHERE `groups`.`user_id` = '33'
ORDER BY `groups`.`id`
I need to get group's ID and group's name for every group he is member in. But results can't duplicate!
My query returns a lot of duplicate entries.
In groups are stored all groups that do exists (name, description etc.). In group_members are stored all users that are members of some group (user_id, group_id etc.).
How to modify this query to get not-duplicate, but correct results? Thanks in advice!
Edit:
In groups there are no user_id. All member of the group are stored in group_members table. I need to get all groups (group's ID and name) where user is member.
groupshas nouser_idon it. If that's the case, your query doesn't return duplicate rows, it fails, because it hasWHERE groups.user_id = 33. Please post the actual table structure and the actual query you're having trouble with, otherwise you're just wasting everyone's time.