Unix Technical Forum

Re: Use of MAX function - right or wrong?

This is a discussion on Re: Use of MAX function - right or wrong? within the Oracle Miscellaneous forums, part of the Oracle Database category; --> "Kay Cee" <cee.1@osu.edu> wrote > Instead of retrieving three data rows with my query (one for each unique > ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-07-2008, 08:53 AM
Billy Verreynne
 
Posts: n/a
Default Re: Use of MAX function - right or wrong?

"Kay Cee" <cee.1@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:24 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com