1

I wrote a quick query

select dno from Employee having max(salary)

In my table, the maximum salary in 96000 and is associated with dno 8. But for some reason, that select statement gives dno 6.

http://hastebin.com/wewahiloki.vhdl

I feel like this is really obvious but I can't figure it out.

TheBandit
  • 109
  • 2
  • 9

2 Answers2

1

If you one to get the "dno" that have the highest salary you can use the following query:

SELECT dno from employee ORDER BY Salary DESC LIMIT 1

The reason is that "having" is used when your are using aggregation operations. See: https://stackoverflow.com/a/2905312/1641558

Community
  • 1
  • 1
Juan Lago
  • 960
  • 1
  • 10
  • 20
1

having don't work properly without group by If you want all the dno with max salary you can use this

select dno from Employee  where salary = (select max(salary) from Employee);
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107