Finding values NOT IN a GROUP BY in Mysql -


i have table similar to:

id    user_id    value ---------------------------- 1     2          colour 2     2          receive_email 3     3          colour 4     3          receive_email 5     3          receive_info 

i group table user_id. want return groups not contain value 'receive_info'. in case above, returned 1 row user_id = 2.

i have tried few things, being latest:

select id, user_id, value   table  group user_id  having value not in('receive_info'); 

i have tried:

select id, user_id, value   table  value not in('receive_info')  group user_id; 

when this, getting records users contain value = 'receive'.

anyone see i'm going wrong?

thanks

select  distinct user_id    tablename   not exists         (             select  1                tablename b               a.user_id = b.user_id ,                     value = 'receive_info'         ) 

or using left join

select  distinct a.user_id    tablename         left join tablename b             on  a.user_id = b.user_id ,                 b.value = 'receive_info'   b.user_id null 

the 2 query output

╔═════════╗ ║ user_id ║ ╠═════════╣ ║       2 ║ ╚═════════╝ 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -