Sql运行多个查询

时间:2013-01-07 22:01:23

标签: php sql

这是我在公司中获得第二高薪的代码......

select salary from org order by salary desc limit(1,1)

上面的结果将是一行......最高薪水(100000),,,现在我想要获得薪水第二高的所有雇员emp_names ..怎么做?

1 个答案:

答案 0 :(得分:3)

将DISTINCT添加到您的查询中(如果多人拥有相同的最高薪水),并按以下方式加入:

select org.* from org
join (select distinct salary from org order by salary desc limit(1,1)) org_salary
  on org.salary = org_salary.salary

工作sqlfiddle here

相关问题