Help! SQL statement

Results 1 to 2 of 2

Thread: Help! SQL statement

  1. #1
    New ASP Guest

    Default Help! SQL statement

    I have a DB like:<BR><BR>==========================<BR>ID &#124 Date &#124 MyData<BR>==========================<BR>001 &#124 July 01 &#124 MyDate 1<BR>001 &#124 July 02 &#124 MyDate 2<BR>001 &#124 July 03 &#124 MyDate 3<BR>:<BR>:<BR>I only want to display the last record in my DB, but the following SQl statement does not work.<BR><BR>SELECT * FROM MYDB<BR>WHERE ID = &#039001&#039 AND DATE = MAX(DATE)<BR><BR>Thank you for your help!!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default ORDER BY ... DESC[ending]

    If this is an Access DB, then do:<BR><BR>SELECT TOP 1 * FROM MyDB <BR>WHERE ID = &#039...&#039 <BR>ORDER BY DATE DESC<BR><BR>If its on most other DBs, just set the CacheSize to 1 after you <BR>create the RecordSet (but before you open it) and leave out the "TOP 1" part. Then simply read the first record and you are done.<BR><BR>The "DESC" there means "DESC"ending...that is, most recent Date first, in this case.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts