Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Suppose there are 2 tables, employee and jobs. Jobid is a FK in employees table referring the jobs table. What is the suitable option to find the rows in employee that violate foreign key constraints?

(a)
SQL
SELECT employee.emp_id,employee.job_id FROM employee LEFT OUTER JOIN jobs ON employee.job_id<>jobs.job_id


(b)
SQL
SELECT employee.emp_id,employee.job_id FROM employee LEFT OUTER JOIN jobs ON employee.job_id=jobs.job_id


(c )
SQL
SELECT employee.emp_id,employee.job_id FROM employee LEFT OUTER JOIN jobs ON employee.job_id=jobs.job_id WHERE (jobs.job_id IS NULL)


(d)
SQL
SELECT employee.emp_id,employee.job_id FROM employee INNER JOIN jobs ON employee.job_id=jobs.job_id WHERE (jobs.job_id IS NULL)
Posted
Updated 10-Apr-14 19:49pm
v2
Comments
Peter Leow 11-Apr-14 0:57am    
Homework is not question.

select * from employee
except
select abc.* from employee inner join jobs on employee.job_id = jobs.job_id
and employee.job_id is not null
 
Share this answer
 
SQL
select employee.emp_id, employee.job_id 
from employee 
left outer join jobs on employee.job_id = jobs.job_id
where employee.job_id is null or employee.job_id <> jobs.job_id
 
Share this answer
 
Comments
Peter Leow 11-Apr-14 0:59am    
Homework is not question.
Ariel Badilles 14-Apr-14 3:58am    
Indeed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900