I am working on a logic where If the LEFT joint field is null then a condition in Where should not be applied. Can some one give me an idea how can It be done with only query.
I tried using IF CASE but its not helping,
Query:
SELECT *
FROM tableA ta
LEFT JOIN tableB tb ON tb.id = ta.id_c
WHERE ta.sales = 'Closed'
AND tb.deleted=0
When ta.id_c is null, the condition in where AND tb.deleted=0 shouldnt taken in to account.
Why? Because when there is a null value in the linking ID there is no selection of data for the query. Any help? thanks in advance.
Expected result: Select columns of the tables.
Actual Table:
tableA:
id_c sales
1 Closed
2 Closed
tableB:
id deleted
1 0
After Query: Current
id_c sales id deleted
1 Closed 1 0
EXPECTED
id_c sales id deleted
1 Closed 1 0
2 Closed NULL NULL
Note: I cannot able to edit the LEFT JOIN conditions