That because you just list all these tables comma separated, without any join condition:
FROM employee E, job_information J, emergency_contact C
This basically performs a cross join, returning a cartesian product of all data.
This should do it, that is, if each of the id's has the same meaning, namely the employee id. I'd suggest having a look at your naming, because 'id' is too generic a name to use like this. As your database grows, you'll have all kinds of ids with different meanings.
SELECT E.id, E.name, E.email, J.title, J.location
FROM
employee E
inner join job_information J on J.id = E.id
inner join emergency_contact C on C.id = E.id
WHERE
(E.id LIKE '%kavi%') OR
(E.name LIKE '%kavi%') OR
(E.email LIKE '%kavi%') OR
(J.title LIKE '%kavi%') OR
(J.location LIKE '%kavi%') OR
(C.earea LIKE '%kavi%') OR
(C.ephone LIKE '%kavi')
In case you have an employee that might not have a job_information or an emergency_contact (which might happen of course), you can use a left join instead of an inner join.
For instance, if you remove the job_information for employee 3, you will only see employee 4 returned by the query above, even though employee 3 still matches the filter 'kavi'. To solve this, use this query:
http://sqlfiddle.com/#!2/4166ae/3
SELECT E.id, E.name, E.email, J.title, J.location
FROM
employee E
LEFT JOIN job_information J on J.id = E.id
LEFT JOIN emergency_contact C on C.id = E.id
WHERE
E.id LIKE '%kavi%' OR
E.name LIKE '%kavi%' OR
E.email LIKE '%kavi%' OR
J.id IS NULL OR
J.title LIKE '%kavi%' OR
J.location LIKE '%kavi%' OR
C.id IS NULL OR
C.earea LIKE '%kavi%' OR
C.ephone LIKE '%kavi'
It basically changes inner join
to left join
, and adds extra conditions to the where clause, allowing the id
s of the detail tables to be null
, indicating that there are no details for that employee.