Preventing entire JOINed MYSQL query from failing when one field is missing within a WHERE clause
Posted
by filip o
on Stack Overflow
See other posts from Stack Overflow
or by filip o
Published on 2010-03-12T06:46:35Z
Indexed on
2010/03/12
6:57 UTC
Read the original article
Hit count: 185
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...
© Stack Overflow or respective owner