Results 1 to 6 of 6
  1. #1
    tonydepo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    28

    2 Records of unique field name

    All, I know there is a very basic SQL, but I can't figure it out. I have one table named "dataset", which includes "Account_NO", "Device". "Date" and "Time". I would like to see only the first 2 records or less of each unique account number/Device.

    Table looks like this:



    Account_no Device Date Time
    00007 123 3/1/2012 11:01:01
    00007 123 3/2/2012 12:02:22
    00007 123 3/3/2012 09:02:44
    00010 335 02/02/2012 01:22:22
    00010 655 02/01/2012 13:33:33

    Result I am looking for:

    00007 123 3/1/2012 11:01:01
    00007 123 3/2/2012 12:02:22
    00010 335 02/02/2012 01:22:22
    00010 655 02/01/2012 13:33:33

    etc...

    Thanks for the help

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tonydepo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    28
    Tried it earlier today, but was getting error on
    Set rs = db.OpenRecordset(SQL). I saw where there was a small SQL to perform based on 2 records per each similar account.

  4. #4
    tonydepo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    28
    Trying to do a sub query, but it is not working.

    SELECT a.ACCOUNT_NO, a.DEVICE_NO
    FROM tblRemovalDataSet AS a
    WHERE (((a.ACCOUNT_NO) In (Select Top 3 ACCOUNT_NO from [tblRemovalDataSet] where [ACCOUNT_NO]=a.[ACCOUNT_NO] and [DEVICE_NO]=a.[DEVICE_NO] Order By [ACCOUNT_NO] desc)));

    Any help? It is not displaying only 3 items per same account_no and same device.... any ideas?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    SELECT A.Account_no, A.Device, A.DateTime
    FROM AccountDev as A
    WHERE A.DateTime IN
    ( Select top 2 datetime from accountdev as B
    WHERE a.account_no = b.account_no)



    Result:

    Account_no Device DateTime
    00007 123 03/01/2012 11:01:01 AM
    00007 123 03/02/2012 12:02:22 PM
    00010 335 02/02/2012 1:22:22 AM
    00010 655 02/01/2012 1:33:33 PM

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    In post #1 you want 2 items, in post# 4 it's 3. In your sample data you show the result you're looking for.

    My solution above was to give you what you said you were looking for.

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

Similar Threads

  1. Count unique records - no duplicates
    By Kevo in forum Queries
    Replies: 4
    Last Post: 08-15-2011, 01:19 AM
  2. Replies: 4
    Last Post: 08-01-2011, 04:24 PM
  3. Count Unique Records
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 08-19-2010, 06:54 AM
  4. Need Help Summing UNIQUE Records
    By Millerguitarworks in forum Access
    Replies: 5
    Last Post: 05-27-2009, 04:37 PM
  5. query that will contain all unique records
    By halcolm1 in forum Queries
    Replies: 0
    Last Post: 01-19-2007, 05:34 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