Results 1 to 10 of 10
  1. #1
    HectorH is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    14

    Selcting max value with all duplicate rows

    Hello,

    I have a table that has information polled hourly over a month period
    equipment, value, day, hour as fields.

    I want to return only the rows that have the max value for each equipment.

    Does anyone know the SQL code? I am able to do it for the equipment and max value but I mess up when I try to include the day and time.

    thanks in advance

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Please post what you have tried etc so we can understand.

    If you're polling by time, where do the duplicates come from?
    What is a duplicate in your terms?

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Is this what you're after?

    http://www.baldyweb.com/LastValue.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    HectorH is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    14
    PBALDY,

    That is the direction I was heading on my latest attempt so Ill use yours as a guide to troubleshoot my code and will let you know if it works for me. Thanks.

  5. #5
    HectorH is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    14
    I got the results, by going thru the acess design after using PBALDYs suggestion. I am going to look at the SQL statement to see how to do it using subqueries Thanks.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help. It's not hard to do as a subquery, but I find it harder to maintain that way, and I often have other uses for the base query anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    HectorH is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    14
    Orange,

    Each day has hr1, hr2, hr3,etc

    Although I got the results. I would like to have it as part of one table instead of being dependent on a query.

    In addition I have some zero reads that I want yo eliminate and I dont want to modify the source table. I am more accustom to using the where statement when joining.

    Pretty much I want to make a new table with just the max value for each equipment. (a month period) I do not want to have it linked to a intermediate query if possible. I know you do subqueries but I am a newbie.

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I agree with Paul that subqueries can be used. Many people still work with a query of a query.

    For info on subqueries see
    http://allenbrowne.com/subquery-01.html

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I said you could use a subquery, but I wouldn't. They can be slower, and from the same site:

    Use stacked queries instead of subqueries. Create a separate saved query for JET to execute first, and use it as an input "table" for your main query. This pre-processing is usually (but not always) faster than a subquery. Likewise, try performing aggregation in one query, and then create another query that operates on the aggregated results. This post-processing can be orders of magnitude faster than a query that tries to do everything in a single query with subqueries.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    HectorH is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    14
    thanks for everyones input. I believe I have enough to do the task and enough to get a better understanding of how to do what i want to more efficently.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-15-2011, 08:40 AM
  2. Query only certain rows?
    By 10 Gauge in forum Queries
    Replies: 48
    Last Post: 03-22-2011, 01:05 PM
  3. Sum of X's in column not rows, possible?
    By CoachBarker in forum Queries
    Replies: 7
    Last Post: 02-09-2011, 12:37 PM
  4. Crushing Rows
    By SCFM in forum Access
    Replies: 4
    Last Post: 03-02-2010, 09:10 AM
  5. Counting rows
    By anishap in forum Access
    Replies: 0
    Last Post: 10-08-2008, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums