[英]Subquery returns more than row
Suppose I had two tables, t_employee and t_leave .假设我有两个表, t_employee和t_leave 。
I would like to print employeeName & substituteEmployeeName .我想打印employeeName和substituteEmployeeName 。
In the t_employee table, there is id of employee and name of the employee.在t_employee表中,有员工的id和员工的姓名。
In the t_leave , there is id of t_leave, employee_id & substitute_id .在t_leave中,有 t_leave 的id 、 employee_id和substitution_id 。
I have tried this code but it will not work.我已经尝试过这段代码,但它不起作用。
SELECT *,
(SELECT t_employee.name FROM t_employee JOIN t_leave WHERE temployee.id=t_leave.substitute_id)
FROM t_leave JOIN t_employee
WHERE t_employee.id=t_leave.employee.id
Can someone help me?有人能帮我吗? Thanks!
谢谢!
You have to LImit it to one, or use Aggregation function LIKE MAX or MIN您必须将其限制为一个,或使用聚合 function LIKE MAX 或 MIN
SELECT *,
(SELECT t_employee.name FROM t_employee JOIN t_leave WHERE temployee.id=t_leave.substitute_id ORDER BY t_employee.name LIMIT 1 )
FROM t_leave JOIN t_employee
WHERE t_employee.id=t_leave.employee.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.