Preventing entire JOINed MYSQL query from failing when one field is missing within a WHERE clause
- by filip o
I am doing a couple of joins with a variable in the WHERE clause. I'm not sure if I am doing everything as efficiently as I could, or even using the best practices but my issue is that half my tables have data for when tableC.type=500, and the other half don't resulting in the entire query failing.
SELECT tableA.value1 , tableB.value2, tableC.value3 FROM tableA
JOIN tableB ON tableB.id=tableA.id
JOIN tableC ON tableC.id=tableB.id
WHERE tableA.category=$var && tableC.type=500;
What I would like to happen is to still get tableA.value1 and tableB.value2 even if there is no field in tableC with a type=500.
any thoughts? i'm totally stumped as how to approach this...