You should not use comma separated value for store collection of id
but use a proper normalizad table
table users
id | name
-----------
1 | Ian
2 | Dave
3 | Mike
table favorites
id , id_user, id_favorite
1, 1, 2
2, 1, 3
3, 2, 1
4, 3, 1
5, 3, 2
select u.id, u.name
from users u
inner join favorites f on f.id_favorite = u.id
where f.id_user = 1
edit by spencer7593
Storing comma separated values in a column is an antipattern. It violates first normal form.
To answer more directly the question that was asked: it is possible to write a MySQL query that returns the specified result.
MySQL provides a FIND_IN_SET function that returns the position of an element found in a comma separated list. Zero is returned when the element is not found.
We can do something like this:
SELECT f.id
, f.name
FROM users f
JOIN users u
ON FIND_IN_SET(f.id,u.favourites)
WHERE u.id = 1
ORDER
BY f.id
Reference: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set