Reputation:
I have two tables one is teacher and another is Department which is mentioned below.
Teacher Table
Id Name
1 xyz
2. Gjd
3. Dftr
4 dhdk
Department Table
Id Name EMPID
1 SQL. 2
2. PHP. 4
3. JAVA. 1
4 PEARL. 5
QUESTION i want those records of teacher which are not link with any Department.
Upvotes: 0
Views: 4193
Reputation: 2348
you can use following statement using left join
then filter Teacher that not matched
SELECT t.*
FROM Teacher t
left join Department d on d.EMPID = t.Id
where d.id is null
Upvotes: 3
Reputation: 1546
you can do it by inner query..
select * from teacher where id not in (select empid from department);
Upvotes: 0
Reputation: 745
SELECT * FROM teachers WHERE
id NOT IN (SELECT DISTINCT EMPID FROM departments) ;
Hope this helps.!!
Upvotes: 0