0

I am trying to get the data from the three table using inner join but its sows me empty result.

select comp.gps_time as complaint_register_date,comp.accept_date as complaint_accept_date,comp.name as citizen_name,comp.road_id,dept.dept_name,circle.circle_name,division.div_name 
from complaints as comp 
   INNER JOIN department as dept ON dept.dept_code=comp.dept_code 
   INNER JOIN circle as circle on circle.circle_code=comp.circle_code 
   INNER JOIN division as division on division.div_code=comp.div_code  
where comp.templateid != null

complaint table

Complaint_Id    Roadid  Dept_code   Div_code    Circle_code Name    Templateid  Accept_date             Gps_time
162            167889       3         1             4        Xyz       3        2019-02-25 09:40:39        2019-02-23 09:40:39
168            167880       2         4             6        abc     null       2019-02-25 09:40:39       2019-02-23 09:40:39

Department table

Dept_code   Dept_name
3           Abcdept
2           Zyzdept
1           syzdept

Circle table

Circle_code Circle_name
4           Xcircle
6           ycircle

Division Table

Division_code   Division_name
1                Ydiv
2                ndiv
4                zdiv
0

You can't test for null using = or <> (or !=)

To test for non-null values you need to use IS NOT NULL:

where comp.templateid is not null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.