php - is not equal sign != and <> is not working in my mysql query -


i using 2 table like, user_details user_id , name field. second table group_user user_id , group_id field. here group_id related group table creating group. want names not in group. using mysql query like,

select      user_details.name       group_users      inner join         user_details          on          group_users.user_id = user_details.user_id       group_id != 160 ; 

or

select      user_details.name       group_users        inner join         user_details         on          group_users.user_id = user_details.user_id       group_id <> 160 ; 

but not getting particular result mean != , <> not working proper.

this should work:

select ud.name  user_details ud left join group_users gu on ud.user_id = gu.user_id , gu.group_id = 160 gu.user_id null ; 

or this

select ud.name  user_details ud ud.user_id not in (    select user_id     group_users gu     gu.group_id = 160 ) ; 

in first, you'd finding users didn't have association group. in second, you'd finding users not in set of users associated group. (same result, depending on data distribution 1 may faster other.)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -