mysql - Joining three tables in SQL, Inner join does not work properly -
we have 3 tables, document
,department
, contact
.
all tables linked 'id' column. want result follows
firstname lastname address upload_date department_name
the below query fetches first 4 columns
select contact.firstname, contact.lastname,contact.address , document.upload_date contact join document on document.id= contact.id , contact.status = 1 , document.defaultdoc=1
so it's inner join.
but fetch last column, department_name
added similar join contact.deptid=department.id
, query returns 0 results. wrong ?
if add
join department on contact.deptid=department.id
it should work.
Comments
Post a Comment