DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: how to find the sal > 2500 without using where clause

  1. #1
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    hi
    how to find the salary of all the employees whos salary is > 2500 without using where clause.

    jegan
    Cheers!
    OraKid.

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    You can use GROUP BY and HAVING clauses. Example:

    SELECT ename, MAX(sal) salary FROM emp
    GROUP BY ename
    HAVING MAX(sal) > 2500;

    Since employee and his sallary are in 1:1 relationship (or even in the same row as in this example), it is irrelevant which group function do you use. It aslo could have been MIN(), AVG(), SUM() etc instead of MAX().

    HTH,
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Good solution, but HAVING is simply a grouped version of WHERE. :)

    I'm wondering why in the world you need to find data but can't use the WHERE.

    - Chris

  4. #4
    Join Date
    Feb 2001
    Posts
    125
    hi,

    I think this will also do (without max() function)

    SELECT ename, sal salary FROM emp
    GROUP BY ename,sal
    HAVING sal > 2500;


    P. Soni

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width