Recently encountered a problem in the project, is very humble, because empty judgment result in the number of data queries out there has been inconsistent, then I screened one by one according to the conditions where the mysql, because there the same field is empty, but when compared appeared to false results.
As follows: travel_type3 is empty
As follows: travel_type3 is null
Questions are as follows:
sql before amended as follows:
select * from exp_oa_appl_header al ,exp_report_oa_header oh,exp_report_header h ,exp_travel_mapping em where al.task_id=oh.task_id and h.oa_header_id=oh.id
AND al.travel_type1 = em.travel_type1
AND al.travel_type2 = em.travel_type2
AND al.travel_type3 = em.travel_type3
and h.requisition_number="BZ202001000498"
Because of the third condition al.travel_type3 = em.travel_type3 cause results to check out the no.
travel_type3 field exp_oa_appl_header al table is empty, exp_travel_mapping of travel_type3 empty, two fields are empty appears, in fact, a field is empty, there is a NUL L, thus resulting in these two fields are not equal.
sql modified as follows:
Used if (exp, true, false) binding SNULL (al.travel_type2) || LENGTH (trim (al.travel_type2)) <1 is determined null method, if the two fields are null or empty, depending on the equal.
select * from exp_oa_appl_header al ,exp_report_oa_header oh,exp_report_header h ,exp_travel_mapping em where al.task_id=oh.task_id and h.oa_header_id=oh.id
and al.travel_type1 = em.travel_type1
AND IF (ISNULL(al.travel_type2) || LENGTH(trim(al.travel_type2))<1,"0",al.travel_type2) = IF (ISNULL(em.travel_type2) || LENGTH(trim(em.travel_type2))<1,"0",em.travel_type2)
AND IF (ISNULL(al.travel_type3) || LENGTH(trim(al.travel_type3))<1,"0",al.travel_type3) = IF (ISNULL(em.travel_type3) || LENGTH(trim(em.travel_type3))<1,"0",em.travel_type3)
and h.requisition_number="BZ202001000498"
After modification, you can check out the article found records: