来自emp表的员工姓名,不属于任何部门 [英] Name for the emploee from emp table which does not belongs to any departmanet
问题描述
Emp_table
empid name
------ ------
1 ramesh
2 ganesh
3 suresh
4 mahesh
5 pranay
dep_table
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
输出
------
名称
nagesh
我尝试过:
i treid使用聚合函数的连接,但没有得到任何人都可以请求帮助....
OUTPUT
------
name
nagesh
What I have tried:
i treid using joins by aggregate functions but not got it can anyone please help in this....
推荐答案
如果我做得好,这应该做的工作
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
它将列出所有没有的雇主Dep_table中的记录
It will list all employers not have a record in Dep_table
根据表格,NOT EXISTS
查询可能比LEFT更有效加入
查询。查询正在做什么也更清楚。
Depending on the tables, aNOT EXISTS
query might be more efficient than aLEFT JOIN
query. It's also clearer what the query is doing.
SELECT
name
FROM
emp_table
WHERE
Not Exists
(
SELECT 1
FROM dep_table
WHERE dep_table.empid = emp_table.empid
)
;
这篇关于来自emp表的员工姓名,不属于任何部门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!