Re: MIN and MAX Query

From: Martin Burbridge <pobox002_at_bebub.com>
Date: 21 Feb 2003 06:16:19 -0800
Message-ID: <45a06b65.0302210616.2fd56884_at_posting.google.com>


"Matty" <matt_at_slippeddisk.fsnenegspamt.co.uk> wrote in message news:<b33k4t$gsq$1_at_news8.svr.pol.co.uk>...
> Thanks for all the replies but I must be doing something stupid cos I get
> errors in them all.
>
> The result I am looking for from the table is as follows:
>
> ENAME SAL
> KING 5000
> SMITH 800
>
<snip>
>
> I now need the WHERE statement for where SAL is at its highest and lowest.
> Can u please help as this is starting to bug me!!

The simplest I can think of is:

SQL> select ename, sal
  2 from emp,
  3 (select max(sal) maxsal, min(sal) minsal from emp)   4 where sal = maxsal or sal = minsal
  5 /

ENAME SAL
---------- ----------

SMITH             800
KING             5000

Note you will not always get two records, you will get all employees that have either the max or min salaries

> BTW I am using Premium Soft MySQL Studio.
>
> Please help!!!!

< other replies snipped>

and I am using SQL*Plus, I would suggest you type in exactly what is shown above in SQL*Plus also, if you have Oracle then you will have that.

If MySQL means the database of that name then I would not be surprised if it did some code mangling before submitting to the db.

Martin Received on Fri Feb 21 2003 - 15:16:19 CET

Original text of this message