Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Emp_table

empid name
------ ------
1 ramesh
2 ganesh
3 suresh
4 mahesh
5 pranay

dep_table

Dep_table                     
 depid         subname       empid
 -------       ------        -------------
 101          cs               4
 102          ec               1
 103          eee              5
 104          mech             2
 105          civil            4


OUTPUT
------
name
nagesh

What I have tried:

i treid using joins by aggregate functions but not got it can anyone please help in this....
Posted
Updated 3-Aug-18 9:04am
Comments
Naga Sindhura 3-Aug-18 4:57am    
output nagesh is not there in the Emp_table then how you are expecting nagesh in the result(output). Could you please update the problem statement correctly.

If I get all right, this should do the Job

SELECT 
  Emp_table.empid,
  Emp_table.name
FROM Emp_table
LEFT JOIN dep_table ON dep_table.empid = Emp_table.empid
WHERE dep_table.depid IS NULL


It will list all employers not have a record in Dep_table
 
Share this answer
 
v2
Depending on the tables, a NOT EXISTS query might be more efficient than a LEFT JOIN query. It's also clearer what the query is doing.
SQL
SELECT
    name
FROM
    emp_table
WHERE
    Not Exists
    (
        SELECT 1
        FROM dep_table
        WHERE dep_table.empid = emp_table.empid
    )
;
 
Share this answer
 

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