'Opposite of WHERE IN SQlite with PHP [duplicate]

I try to make a sharing function in my PHP application.
Every User has an ID and can read his own project and should read the projects, where his ID is in the can_read_by array.

project_id  user_id     can_read_by
1           7           2,3,4
2           6           3
3           2           5
4           1           2
5           5           3,1

How do i, to serve the user 2 the projects: 1, 3 and 4?

edit:

new question: Get many Id`s with WHERE in SQlite with PHP



Solution 1:[1]

Use the operator LIKE in the WHERE clause:

SELECT *
FROM tablename
WHERE user_id = ?
   OR ',' || can_read_by || ',' LIKE '%,' || ? || ',%';

Change ? with the user's id that you want.

See the demo.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 forpas