Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL

Re: SQL

From: Gary O'Keefe <gary_at_onegoodidea.com>
Date: Wed, 21 Jul 1999 14:04:18 GMT
Message-ID: <3795cec6.103845285@news.hydro.co.uk>


On Wed, 21 Jul 1999 12:46:14 GMT, narana_at_my-deja.com wrote:

>How do i get (using sql) the top x salary using the emp table?????
>
>eg emp1 salary 10
> emp2 salary 5
> emp3 salary 6
> emp4 salary 8
> emp5 salary 3
> emp6 salary 2
>
>to get the top 3 earners result will be
>
> emp1 salary 10
> emp4 salary 8
> emp3 salary 6
>
>
>How can i get this result using sql ????????

Using Oracle (and why not, this is comp.databases.oracle.misc):

SELECT *
FROM emp
ORDER BY salary DESC

and for the second example:

SELECT *
FROM emp
WHERE rownum <= 3
ORDER BY salary DESC

Tip: Get a copy of "ORACLE8: The Complete Reference" by George Koch and Kevin Loney (ISBN 0-07-88-2396-X, $59.99) from just about any book shop with a computing section. It's (IMO) the best and most complete Oracle book for a newbie, plus you'd never have asked the question if you'd read it.

Tip 2: Don't you think that 8 question marks are a bit excessive???????? Don't you think that one on its own looks just a teensy bit more classy?

Gary
--
Gary O'Keefe
gary_at_onegoodidea.com

You know the score - my current employer has nothing to do with what I post Received on Wed Jul 21 1999 - 09:04:18 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US