Results 1 to 8 of 8
  1. #1
    cyberdoc is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    5

    query to get only last entry for every user

    Hi guys,
    ive a table with entries of users and the orders they made and payments details etc. now i need a query wherein only the latest orders for all users are shown and not all of them. for example,


    ORDERID | USERID | ORDERDATE | AMOUNT | PAID | BALANCE |
    ORD0001 | USR0001| 12/2/17 | 1500 | 1200 | 300 |
    ORD0002 | USR0002| 12/2/17 | 400 | 210 | 190 |


    ORD0003 | USR0002| 12/2/17 | 1000 | 800 | 200 |
    ORD0004 | USR0003| 12/2/17 | 500 | 200 | 300 |


    SO in this we would want
    only order 3 to be shown for user2 and not order2.
    Thanks in advance

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    How will you differentiate between two orders from customer2 on 12/2/17 and 12/2/17


    Sent from my iPhone using Tapatalk

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Create a grouped query with max in the date field



    https://support.office.com/en-gb/art...__toc258021887


    Sent from my iPhone using Tapatalk

  4. #4
    cyberdoc is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    5
    the one with higher order number is the later one and needs to be retrieved. order number is the unique id hence no duplicacy

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Ok group the customer id and max the orderid


    Sent from my iPhone using Tapatalk

  6. #6
    cyberdoc is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    5
    Quote Originally Posted by andy49 View Post
    Ok group the customer id and max the orderid


    Sent from my iPhone using Tapatalk
    but the problem is i need the other fields also and not only these two.. it doesnt work, try oncee

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Can I see your current sql? Or a design view?


    Sent from my iPhone using Tapatalk

  8. #8
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Ok I'm sure there's a shorter route but get the most recent orderid and user (2 field grouped query) and call it qryorder. Then create another query with qryorder and your original table left joined on the orderid fields.


    Sent from my iPhone using Tapatalk

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

Similar Threads

  1. Multi user data entry
    By FJM in forum Access
    Replies: 5
    Last Post: 01-07-2015, 02:27 AM
  2. duplicate entry flag to user
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 06-14-2012, 11:13 AM
  3. Replies: 1
    Last Post: 12-15-2011, 04:26 AM
  4. Replies: 3
    Last Post: 12-20-2010, 11:35 AM
  5. If Statements with user entry too
    By jheintz57 in forum Programming
    Replies: 1
    Last Post: 09-15-2010, 02:37 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