Please tell me how to select records by specific parameters. For example, in the database there is a table users with the following fields.

enter image description here

how to get all records from this table where user or place is 2 then go through the chain 4,5,6 because The first digit met on id = 4, then the search 4 is going on, and id4 is found on id = 5 and so on until the end. From this example, it is expected to get the following output

id - 4,5,6

    1 answer 1

    Weak condition. But if you try to do it exactly, you’ll

    SELECT u.id FROM users u, (SELECT id FROM users WHERE 2 IN (user, place) ) x WHERE (u.id > x.id AND u.user = x.id) OR u.id = x.id ORDER BY 1 ASC;