我编写了Mysql查询,该查询从employee表中提取了第六大薪水。我经历了其他堆栈溢出链接,也请不要使其重复。
我的查询是如何通过子查询中的限制。
下面的代码是内部联接的哪一个工作正常
select e1.first_name,e1.salary
from employees e1
inner join (select employee_id
from employees
order by salary desc limit 6) as e2
on e1.employee_id = e2.employee_id
order by salary asc limit 1;
| first_name | salary |
+------------+--------+
| Barby | 164588 |
当我在子查询中写时传递子查询中的限制抛出错误
select first_name,salary
from employees
where employee_id in (select employee_id
from employees
order by salary desc **limit 6** )
order by salary desc limit 6;
| first_name | salary |
+------------+--------+
| Jacklyn | 166976 |
| Carissa | 166765 |
| Riley | 166569 |
| Lauren | 166016 |
| Lucy | 165660 |
| Barby | 164588 |
下面是我想在子查询中写的而不是Joins
| first_name | salary |
+------------+--------+
| Barby | 164588 |