Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    Oakland, CA
    Posts
    126

    Unanswered: Query with Criteria only for latest date

    I have a table that has a field with date records. How do I build a query that pulls only the latest date(s) (it might pull multiple records)?

  2. #2
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    could u explain a little further?
    field names, no. fields...etc, field functionality,

  3. #3
    Join Date
    Nov 2002
    Location
    Oakland, CA
    Posts
    126
    It's that simple, imagine table with one field - DATE. it has 3 records, 8/30, 8/30, and 8/28. How do I build the query to select only the latest date (in this case 8/30 so the final outcome would be 2 records)

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select datefld
      from yourtable
     where datefld
         = ( select max(datefld) from yourtable )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    but that would only show the max date; it wont show the associated ID field; if u try doin max on date with ID field, it wont show max date;

    if ur tryin to get the ID associated with the max date, you can make a query with the info above this (max date) and then in a new query, link ur table date field to the date field from the queyr, and u can get ur file numbers.

    I dont think thats the fastest way, there might be a faster way?

  6. #6
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    259
    sry, mistake; the SQL statement already does that in the =(Select...)
    just + select ID before datefld in the first line;

Posting Permissions

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