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: Use of MAX function - right or wrong?

Re: Use of MAX function - right or wrong?

From: Billy Verreynne <vslabs_at_onwe.co.za>
Date: 10 Jul 2003 01:56:31 -0700
Message-ID: <1a75df45.0307100056.4fae2a73@posting.google.com>


"Kay Cee" <cee.1_at_osu.edu> wrote

> Instead of retrieving three data rows with my query (one for each unique
> Item_No), all I'm returning is the data row with Item_No 003 because it's
> the one with the most current date. Can someone shed some light on where I
> went wrong? Here's one of my SQL statements:
>
> SELECT item_no, date FROM tablename
> WHERE date =
> (SELECT MAX(date) FROM tablename)

Not only incorrect sql, but crap sql IMO. Why on earth just not use plain sql instead as it *should* be used?

SELECT
  item_no,
  MAX(date) as MAX_DATE
FROM table
GROUP BY item_no
ORDER BY 1 ROW-BY-ROW processing (as what you are attempting) is a *BAD* *HABIT*. It will bite you in the butt, kick you in the nuts, steal your credit card and sleep with your wife/boyfriend/dog when you least expect it.

Always aim for processing _data_ with SQL. Not individual rows.

--
Billy
Received on Thu Jul 10 2003 - 03:56:31 CDT

Original text of this message

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