-1

I have column likes where i store ids in a in comma separated string: 76,88

I want to select row from another table whose id is in 78,88

I tried using MYSQL IN() function but it only get first id 78

so how do i solve it in the same query string?

SELECT  u.user_id,
        u.username,
        u.firstname,
        u.lastname,u.status

        FROM users u WHERE u.user_id IN(
            SELECT likes FROM posts WHERE post_id='200'
        )

Thank you.

james Oduro
  • 673
  • 1
  • 6
  • 22

1 Answers1

0

FIND_IN_SET() function returns the position of a string within second string. Returns zero when search string doesn’t exist in string list.

SYNTAX:

FIND_IN_SET(argument1,argument2)

SQL will look like this:

SELECT  u.user_id,
        u.username,
        u.firstname,
        u.lastname,u.status

        FROM users u WHERE FIND_IN_SET(u.user_id,
            (SELECT likes FROM posts WHERE post_id='200') 
        )

Note: argument1 is a string to check against comma separated string in argument2

james Oduro
  • 673
  • 1
  • 6
  • 22