1 Reply Latest reply: Nov 15, 2013 12:16 AM by jariola RSS

    Is these query Valid??

    krishnagopi614

      51) Display the name of the employee who earns highest salary. I wrote like this "select last_name from employees  having max(salary)=salary" ; it gave an error like 'SQL Error: ORA-00937: not a single-group group function 00937. 00000 -  "not a single-group group function" Can anybody explain what the error is????????????????

        • 1. Re: Is these query Valid??
          jariola

          Hi,

           

          Unfortunately your query is not valid. You can try

           

          WITH qry AS (
            SELECT  last_name,
              salary,
              ROW_NUMBER() OVER(ORDER BY salary DESC) AS rn
          FROM employees
          )
          SELECT last_name,
            salary
          FROM qry
          WHERE rn =1
          
          
          

           

          Or

           

          WITH qry AS (
          SELECT  last_name,
            salary,
            max(salary) OVER() as max_sal
          FROM employees
          )
          SELECT last_name,
          salary
          FROM qry
          WHERE max_sal = salary
          
          

           

          Regards,

          Jari