I have this working MySQL query (it's stripped down to show only relevant lines):
SELECT
c.id AS id_comment
, bl.id_user AS block
FROM comments AS c
LEFT JOIN user_blocked AS bl ON
(c.id_user = bl.id_user AND :uid = bl.id_user_blocked)
OR (c.id_user = bl.id_user_blocked AND :uid = bl.id_user)
WHERE (c.id_title = :idt)
It works! But I just want to get results where block IS NULL
so I add a new condition in WHERE
:
SELECT
c.id AS id_comment
, bl.id_user AS block
FROM comments AS c
LEFT JOIN user_blocked AS bl ON
(c.id_user = bl.id_user AND :uid = bl.id_user_blocked)
OR (c.id_user = bl.id_user_blocked AND :uid = bl.id_user)
WHERE (c.id_title = :idt) AND (block IS NULL)
But I get this error:
SQL ERROR: SQLSTATE[42S22]: Column not found: 1054
Unknown column 'block' in 'where clause'
Why? What am I doing wrong?