sort query result without selecting that column but sort by that column?

Mr.Chowdary picture Mr.Chowdary · Jul 19, 2012 · Viewed 27.2k times · Source

I have a query, I have to sort the result from the DB2 database. The query will select the columns empname,salary,status. But I have to sort the result using order by empno
But the query is not working.. This is the query.

select empname, salary, status from emp where salary>5000 order by empno  

Can you update the query to sort by empno without using it in selecting columns?

Answer

jaychapani picture jaychapani · Jul 19, 2012

Your syntax seems correct to me except dot(.) at the end. After removing dot if doesn't work...

Try something like

SELECT empname, salary, status
  FROM (SELECT   *
            FROM emp
        ORDER BY empno)
 WHERE salary > 5000