I have the following query:
SELECT table_a.field1, table_b.field1
FROM table_a, table_c
LEFT JOIN table_b
ON table_a.field1=table_b.field1
WHERE table_a.field2 LIKE ?
AND table_a.field3 = ?
AND table_a.field4 = ?
AND table_b.field1 IS NULL
AND table_c.id = table_b.c_id
AND table_c.field1 = ?
AND table_c.field2 = ?
AND table_c.field3 = ?
However when executed I get the following error:
o: SQLSTATE[42P01]: Undefined table: 7 ERROR: invalid reference to FROM-clause entry for table "table_a" at character 114
HINT: There is an entry for table "table_a", but it cannot be referenced from this part of the query.
I’m using PostgreSQL and PDO.
Any idea how to fix this / what’s wrong with my query?
This:
appears to be trying to left-join
table_candtable_busing a column intable_aand that doesn’t make that much sense. Try rewriting the whole FROM like this:Also note that I’ve moved the join condition for
table_candtable_binto the FROM clause so you won’t need it in the WHERE clause anymore.