>heh actually it confused me a touch.  I believe that I understand
>what you're saying though I don't know what TOP type records are.
>Maybe I should specify my situation.    I'm doing a "WHAT'S NEW"
>section of a web page.  I want the 3 most recently entered items.
>I've adjusted my current query to my understanding.  Is this right?
>
><CFQUERY NAME="whatsnew" DATASOURCE="dpch">
>        (
>              select * FROM whats_new
>              WHERE dateAdded > #dateAdd("d",-7,Now())#
>              order by dateAdded DESC
>        )
>        WHERE ROWNUM < 4
></CFQUERY>
>
>I originally had the ROWNUM < 4 along with the other WHERE with an AND.
>

Not quite. Further, I loathe the use of * in queries. It should be something
like:

SELECT mycolumn1,
mycolumn2
FROM (
  SELECT mycolumn1,
    mycolumn2
  FROM whats_new
  WHERE dateAdded > sysdate-7
  ORDER BY dateAdded DESC
)
WHERE rownum <= 3

I did a few things:

1) Put the correct syntax in to get the 3 most recent items
2) Removed the CF function you're using to get 7 days ago and used Oracle's
built-in sysdate function instead
3) changed rownum < 4 to rownum <= 3. This one's just personal preference,
but I don't have to "think" this way about how many records are coming back.
I see "3" and I just know.
4) Intentionally removed the *. I hate using * even if I'm using all my
columns because it's more of an effort for a subsequent developer to come in
and read my code and know exactly what's coming back. Further, * is
technically a bit slower because Oracle then has to use its system lookup
tables to get the column names in the whats_new table.

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to