Query for latest record

Results 1 to 2 of 2

Thread: Query for latest record

  1. #1
    Join Date
    Dec 1969

    Default Query for latest record

    I&#039;m trying to Select the record with the most recent insert date. I have a field that uses "getdate()" to record when the record was created. Help!<BR>

  2. #2
    Join Date
    Dec 1969

    Default ORDER BY dateField DESC

    SELECT TOP 1 * FROM tablename ORDER BY dateField DESC<BR><BR>alternate idea:<BR><BR>SELECT * FROM tablename <BR>WHERE dateField IN<BR>( SELECT Max(dateField) FROM tablename )<BR><BR>Though the second one would return more than one record if multiple records had the same dateField value. On the other hand, the first one will return one of the records with the same max dateField value, but you won&#039;t know which one (unless you add more to the ORDER BY clause). So it is your choice.<BR><BR>Do you see why either one would work? Depending on what you want?<BR><BR><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