Answer the question
In order to leave comments, you need to log in
How to select records that have 2 or more related records in another table?
How to select records that have 2 or more related records in another table?
for such a scheme:
That is, if there are 2 directions or more by id_history, then choose.
Step 2 - then from these two selected, choose the one with the smallest id;
Answer the question
In order to leave comments, you need to log in
I'm scared to go to the clinic now.
Would you at least suggest some table names for clarity, so as not to compose A and B.
SELECT rr.*
FROM (
SELECT MIN(r.id) AS id
FROM recept r
JOIN history h ON r.id_history = h.id
GROUP BY r.id_history
HAVING COUNT(r.id) >= 2
) ids
JOIN recept rr ON rr.id = ids.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question