M
M
Messi2018-02-01 17:44:18
MySQL
Messi, 2018-02-01 17:44:18

How to get matched values?

I have entries:
car_id user_id created_at count
26 1 - -
27 1 - -
27 8 - -
I need to get users who have the same car_id knowing only user_id. How can I do that?
because I write user_id IN (1, 8) displays 3 records.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2018-02-01
@FitTech

SELECT
*
FROM tablename t 
JOIN tablename t2 ON t2.user_id IN (1, 8) AND t2.user_id != t.user_id AND t2.car_id = t.car_id
WHERE t.user_id IN (1, 8)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question