1

I am try to run sub query with NOT IN keyword

SELECT DISTINCT(user_id) FROM user_group_master WHERE user_id IN (SELECT GROUP_CONCAT("'",userid,"'") FROM location_sharing_setting WHERE owner_id = '123456' AND sharing_status = 0)

Query is running properly when we didn't use sub query

SELECT DISTINCT(user_id) FROM user_group_master WHERE user_id NOT IN ('56556','540003')

Please Help me with best solution ...

Thakur
  • 13
  • 2
  • this may help you http://stackoverflow.com/questions/13451605/how-to-use-group-concat-in-a-concat-in-mysql –  May 24 '16 at 09:12

1 Answers1

1

You don't need GROUP_CONCAT to use IN() :

SELECT DISTINCT(user_id) 
FROM user_group_master
 WHERE user_id IN (SELECT user_id
                   FROM location_sharing_setting
                   WHERE owner_id = '123456' AND sharing_status = 0)

You can either specify a list inside the IN() statement, like '123','234',.. .

Or you can specify a query, that output the same column like

SELECT * FROM Table
WHERE Col IN(SELECT Same_Col FROM OtherTable)
sagi
  • 40,026
  • 6
  • 59
  • 84