Answer the question
In order to leave comments, you need to log in
There are 3 tables (A, B, C). B - connective (many-to-many). How to select all records from A but specific?
There are 3 tables (A, B, C). B - connective (many to many).
Table A id | title
Table B A_id | С_id
Table C id | code
We need to select all records from A, but in a specific way. If a record from table A has code 1 in table C, then it should be in the results, if code = 0, then exclude it.
Example:
A
id | title
1 | title 1
2 | title 2
3 | title 3
A_id | С_id
1 | 1
1 | 2
2 | 3
3 | 4
id | code
1 | 0
2 | 1
3 | 0
4 | 1
Answer the question
In order to leave comments, you need to log in
SELECT * FROM A
INNER JOIN B
ON A.id = B.A_id
INNER JOIN C
ON B.B_id = C.id
GROUP BY A.id
HAVING C.code = 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question