Say
Table A Table AB Table B
+----+---------+ +-----+-----+ +----+-----+
| id | name | | ida | idb | | id | age |
+----+---------+ +-----+-----+ +----+-----+
| 1 | 'one' | | 1 | 3 | | 3 | 3 |
+----+---------+ +-----+-----+ +----+-----+
| 2 | 'two' | | 2 | 4 | | 5 | 5 |
+----+---------+ +-----+-----+ +----+-----+
| 3 | 'three' | | 2 | 5 |
+----+---------+ +-----+-----+
What I want What I get
+---------+------+ +---------+------+
| name | age | | name | age |
+---------+------+ +---------+------+
| 'one' | 3 | | 'one' | 3 |
+---------+------+ +---------+------+
| 'two' | 5 | | 'two' | 5 |
+---------+------+ +---------+------+
| 'three' | NULL | | 'two' | NULL |
+---------+------+ +---------+------+
| 'three' | NULL |
+---------+------+
My sql is
SELECT A.name, B.age
FROM A
LEFT JOIN AB
ON A.id = AB.ida
LEFT JOIN B
ON AB.idb = B.id
Constraints: I don’t want to use Where statement for specific reasons, nor sub-queries for performance reason.
Is there a way I could only get the records where the relation AB matches something that exists only using JOIN/ON and no sub-queries?
Use grouping.
Or you could use right joins.