This is query I have at the moment:
SELECT
`groups`.`id`,
`groups`.`name`,
`groups`.`description`,
`groups`.`members`,
`groups`.`image`,
FROM
`groups`
WHERE
`groups`.`name` LIKE '%a%'
OR
`groups`.`description` LIKE '%b%'
All works as expected, but I need one additional thing to select. Problem is that its stored in another table and I’m not so good with joins. Here is 2nd table structure:
group_members
group_id,user_id,status;
I need to select specified user status for group! Is it possible? How?
Thanks in advice!
Edit:
I need to display all groups and current user status in each of those groups.
Edit #2:
Lets say that user_id is set to 33. He types aa as group name and in results he see all groups that have aa in its name. In addition, in results are his status in each group.
ID Name Description Status
2 aa2 foobar 3
2 aa1 foobar 1
4 aa3 foobar
6 aa3 foobar
5 aa3 foobar 2
Edit #3:
Here is almost what I need…
SELECT `groups`.`id`, `groups`.`name`, `groups`.`description`, `groups`.`members`, `groups`.`image`, `group_members`.`status`
FROM `groups`
LEFT JOIN `group_members`
ON (`group_members`.`group_id` = `groups`.`id`)
WHERE `group_members`.`user_id` = '33'
AND `groups`.`name` LIKE '%%'
OR `groups`.`description` LIKE '%%'
Only problem, I does not select groups where I’m not member. Interesting why… I did use ‘left outer’ join.
if i understand you , its very easy to add a join, like :