So I have this table:
history_table
+------------+----------+----------+--------+---------+--------------+--------------+------+---------+
| history_id | TDNO | titleNO | lotNO | area | encumbrances | assess_value | EFF | memo_id |
+------------+----------+----------+--------+---------+--------------+--------------+------+---------+
| 145 | F-111111 | T-00000 | LOTF1 | 500 SQM | NONE | 12331.13 | 2016 | 415 |
| 146 | F-000000 | T-000000 | LOT F0 | 1 HA | NONE | 123.23 | 2015 | 412 |
| 147 | E-000000 | T-00000 | LOTE0 | 500 SQM | NONE | 13123.12 | 1994 | 413 |
+------------+----------+----------+--------+---------+--------------+--------------+------+---------+
memoranda
+---------+--------------+
| memo_id | memo_string |
+---------+--------------+
| 0 | |
| 412 | TEST. |
| 413 | TEST2. |
| 415 | Test3. |
+---------+--------------+
td_ownersinfo
TD_NO owner location transaction
-------- -------------- -------- -------------
F-000000 name1 SAN JOSE TRANSFER
F-111111 name2 LAS VEGAS WALK-IN
So I have this query:
SELECT
history_table.`history_id`,
history_table.`TDNO` AS 'TAX DECLARATION NO',
history_table.`titleNO` AS 'TITLE NO',
history_table.`lotNO` AS 'LOT NO',
history_table.`area` AS 'AREA',
history_table.`encumbrances` AS 'ENCUMBRANCES',
FORMAT(history_table.`assess_value`, 2) AS 'ASSESS VALUE',
history_table.`EFF`,
history_table.`memo_id`,
memoranda.`memo_string` AS MEMORANDA,
TD_ownersinfo.`owner`,
TD_ownersinfo.`location`,
TD_ownersinfo.`transaction`
FROM
history_table
INNER JOIN memoranda
ON memoranda.memo_id = history_table.memo_id
LEFT JOIN td_ownersinfo
ON history_table.TDNO = td_ownersinfo.TD_NO
WHERE history_table.TDNO LIKE '%%'
AND history_table.titleNO LIKE '%%'
AND td_ownersinfo.owner LIKE '%%'
AND td_ownersinfo.transaction LIKE '%%'
AND td_ownersinfo.location LIKE '%%'
OR TD_ownersinfo.`TD_NO` IS NULL
ORDER BY history_table.history_id
And the result is like this:
history_id TAX DECLARATION NO TITLE NO LOT NO AREA ENCUMBRANCES ASSESS VALUE EFF memo_id MEMORANDA owner location transaction
---------- ------------------ -------- ------ ------- ------------ ------------ ------ ------- ------------------- -------------- -------- -------------
145 F-111111 T-00000 LOTF1 500 SQM NONE 12,331.13 2016 415 TEST3. name2 LAS VEGAS WALK-IN
146 F-000000 T-000000 LOT F0 1 HA NONE 123.23 2015 412 TEST. name1 SAN JOSE TRANSFER
147 E-000000 T-00000 LOTE0 500 SQM NONE 13,123.12 1994 413 TEST2. (NULL) (NULL) (NULL)
But when I try to put value in history_table.TDNO LIKE '%%' the TDNO that has null value in td_ownersinfo table will still be displayed. For example, I will put value in history_table.TDNO in the same query: history_table.TDNO LIKE '%F-111111%'. The result will be like this:
history_id TAX DECLARATION NO TITLE NO LOT NO AREA ENCUMBRANCES ASSESS VALUE EFF memo_id MEMORANDA owner location transaction
---------- ------------------ -------- ------ ------- ------------ ------------ ------ ------- ---------- -------------- -------- -------------
145 F-111111 T-00000 LOTF1 500 SQM NONE 12,331.13 2016 415 TEST3. name2 LAS VEGAS WALK-IN
147 E-000000 T-00000 LOTE0 500 SQM NONE 13,123.12 1994 413 TEST2. (NULL) (NULL) (NULL)
I know the problem is in the WHERE clause where I use OR in OR TD_ownersinfo.TD_NO IS NULL, is there any way to solve this?
ORclause to fix your issue?ORclause, TheTAX DECLARATION NOwith null values ofowner, location, transactionwill not be displayed. I want to display all the data even if there is a null value but