sql IN keyword and multiple input columns - how to combine into a single column

44
March 05, 2021, at 3:00 PM

I have some sql that is not doing what I want. I would like the CONCAT statement to produce a single list of id numbers. As it is now I get a column that has in it "number, number". I want one column of integers. I am using the IN keyword.

SELECT DISTINCT visible
     , num
     , date_now
     , show_message
     , show_exercise
     , show_workout
     , picture_large
  FROM feed 
 WHERE feed.from_user_id IN 
    ( SELECT DISTINCT 
      CONCAT(friends.user_id, ', ', friends.friend_user_id ) 
      FROM friends 
      WHERE  friends.user_id = 1 
        OR friends.friend_user_id = 1 
    ) 
ORDER BY feed.date_now DESC 

How do I properly make use of the IN keyword with multiple columns as an input??

Answer 1

You are looking for the function group_concat() instead of concat() and you want to group by whatever that will generate a single row with the values you want.

Answer 2

Not sure I understand your question correctly. But is this what you are looking for?

SELECT DISTINCT 
visible, num, date_now, show_message, show_exercise, show_workout, picture_large
FROM feed WHERE feed.from_user_id IN 
    ( SELECT friends.user_id
      FROM friends 
      WHERE  friends.user_id = 1 
union 
SELECT DISTINCT 
     friends.friend_user_id 
      FROM friends 
       friends.friend_user_id = 1 
    ) 
ORDER BY feed.date_now DESC 
READ ALSO
Convert existing array into group php [closed]

Convert existing array into group php [closed]

Want to improve this question? Add details and clarify the problem by editing this post

60
Accessibility issues with nvda

Accessibility issues with nvda

I have dynamic div which will be added to the HTML page on the flyit's selection dropdown

34
Use multiprocessing sharing memory without pickling large object in Python

Use multiprocessing sharing memory without pickling large object in Python

I did some research, but still don't find an answerIs it possible to create a sharing memory object for multiple processes without pickling the large object?

60
Cannot read enum property, ClassCastException

Cannot read enum property, ClassCastException

For my model I have problem with reading enum propertyAfter reading from mongoDB, the property 'value' has type String instead of MyEnum

78