Results 1 to 2 of 2
  1. #1
    CobraKai is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2019
    Posts
    5

    How to create a complex query (inner join, sort by ID and time, cut list)?

    Hello!



    I am looking for help to find a solution for following problem:

    I have 2 tables - 1st table contains data about goods (name, number, date of creation over years, parts are repeated many times with different date, different batch number and differnet classifcation like OK/NOK), 2nd table contains only a few goods with ID number.

    Target:

    List parts from 1st table which are in 2nd table but I should show only latest 3 date for each listed part (from 1st table).

    List should look like this:

    A - 28.06.2019
    A - 27.06.2019
    A - 26.06.2019
    B - 28.06.2019
    B - 25.06.2019
    B - 24.06.2019
    C - 25.06.2019
    C - 23.06.2019
    C - 21.06.2019

    How should I start with it? I can join tables order them by ID number but I can't select only 3 pcs from each part number.

    Thanks for help.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    you'll need to use a subquery to join on date

    the query might be something like

    Code:
    SELECT *
    FROM tbl1
    where tbl1.crDate=(SELECT TOP 3 crDate FROM tbl1 D WHERE partno=tbl1.partno ORDER BY crDate DESC)
    note the D alias in the subquery

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

Similar Threads

  1. Query is too complex to create report
    By chriswrcg in forum Reports
    Replies: 10
    Last Post: 11-03-2018, 09:30 AM
  2. Replies: 1
    Last Post: 03-21-2018, 07:50 PM
  3. Replies: 6
    Last Post: 11-19-2013, 01:38 AM
  4. Complex Sort
    By Jojojo in forum Queries
    Replies: 7
    Last Post: 10-18-2011, 09:40 PM
  5. SQL For Complex Inner Join
    By compooper in forum Queries
    Replies: 1
    Last Post: 07-26-2011, 08:18 AM

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