MySQL LEFT JOIN Multiple Conditions -


i have 2 tables: , b linked "group_id".
2 variables i'm using: $keyword, $_session['user_id']

a
group_id
keyword

b
id
group_id
user_id

i want able select groups user not in based on keyword search.

therefore goal select rows in user_id!={$_session['user_id'} corresponding group_id in b , keyword.

this tried:

select a.*   left join b on a.group_id=b.group_id  a.keyword '%".$keyword."%'  , b.user_id!=$_session{['user_id']}  group group_id 

however, not find rows (matches) unless remove and b.user_id!=$_session{['user_id']} in case include groups user in - not want.

any appreciated! thanks

just move condition join on criteria, way existence of b not required return result

select a.*      left join b on a.group_id=b.group_id , b.user_id!=$_session{['user_id']}      a.keyword '%".$keyword."%'      group group_id 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -