I need to select records using a condition added only if a field value exists. My query uses a left join between table A and B, and table B may not have a record for every record in table A, so fields selected from B may have null values. If the value for field B.1 exists so is not null then I want to add a condition to the where clause. Is this possible? I tried the following:
select A.field1, B.field2 from A, B where A.field1='somevalue' and (select case when B.status=1 then B.customers_group_id=2 else 1=1)
But it gave a check syntax error in PhpMyAdmin.