This code created the error.
Error Code: 1052. Column 'ID' in where clause is ambiguous
SELECT h1.name, h1.gender,h2.gender
FROM hampster h1, hampster h2,partner p
INNER JOIN partner on h1.ID = partner.ID1
INNER JOIN children on h2.ID = children.ID1
WHERE h1.id = p.id1
AND h2.id = p.id2
AND h1.gender = h2.gender
AND EXISTS (SELECT c.id1
FROM children c
WHERE c.id1 = p.id1
OR c.id1 = p.id2)
ORDER BY h1.gender, h1.name;
This is created when I add hampsters h2 into my query. My goal is to use inner join to combine two instances of the hamspter table and still use 'h1' and 'h2' to refer to them.
This is the expected output from the query
h1.name h2.name gender
Alex King 0
Grant Alex 0
Jack Grant 0
Cathy Amy 1
Trish Amy 1