I have a very confusing database with a table that holds two values I need in a separate table. Here is my issue:
Table1
- id
Table2
- id
- table1_id
- tabl
If you join a table several times, use aliases to distinguish them:
SELECT table1.id,table2.id,table2.table3_id_1,table2.table3_id_2,t3_1.id,t3_2.id
FROM table1
JOIN table2 ON table1.id=table2.table1_id
JOIN table3 t3_1 ON table2.table3_id_1=t3_1.id
JOIN table3 t3_2 ON table2.table3_id_2=t3_2.id
WHERE ... t3_1.id=... AND ... t3_2.id=...