Access 2000 query problem - Help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tehswinstead@gmail.com

    #1

    Access 2000 query problem - Help!





    Hi, I have a problem that I'm pulling my hair out over.

    I work at a company that legally has to test the blood lead levels of
    it's employees.
    Each person must be tested every 6 months. I have the results in a
    database as shown below.
    (If it doesn't show up in a fixed width font google groups users can
    click the top right link to fix it)


    _______________ _______________ _______________ _______________ _______________ _________
    | BloodTesting.md b
    |
    |
    |
    | ___________ ___________
    ___________ |
    | | | | | |
    | |
    | | EMPLOYEES | | RESULTS | |
    TESTS | |
    | |___________| |___________|
    |___________| |
    | | | | | |
    | |
    | | id | | id | |
    id | |
    | |___________| |___________|
    |___________| |
    | | | | | |
    | |
    | | name |--------------------| emp_name | |-----|
    date | |
    | |___________| |___________| |
    |___________| |
    | | | | | |
    |
    | | startdate | | result | |
    |
    | |___________| |___________| |
    |
    | | | | | |
    |
    | | leavedate | | testdate |------------|
    |
    | |___________| |___________|
    |
    | | |
    |
    | | untilnext |
    |
    | |___________|
    |
    |
    |

    |______________ _______________ _______________ _______________ _______________ __________|

    I'm trying to make a query that will show me any employee whose last
    test date is more than 6 months ago (i.e. they are overdue). I can do
    this easily enough for employees with only one result - select emp_name
    from results where dateadd("m", 6, testdate) < date(); - but anyone
    with us for more than 6 months (or employees with high lead levels in
    their blood get monitored every 3 months) will have more than one
    result and I'm finding it hard to query only each person's most recent
    test date.

    I've tried playing around qith queries and subqueries and macros and
    modules and for a while I thought I'd found the key in using DISTINCT
    along with "order by testdate limit 1" but that didn't work either.

    Can anybody point me in the right direction on this please?

  • pietlinden@hotmail.com

    #2
    Re: Access 2000 query problem - Help!

    Select EmployeeID, Max(TestDate) As LastTestDate
    FROM EMPLOYEE
    ORDER EMPLOYEE.Employ eeID
    GROUP BY EmployeeID

    Then you can get all their data using that and the original table.

    Comment

    • tehswinstead@gmail.com

      #3
      Re: Access 2000 query problem - Help!

      Not at work now so I can't test it but my first thought is, wouldn't
      that give me the most revent test date in the table rather than each
      employees most recent one?

      Comment

      • pietlinden@hotmail.com

        #4
        Re: Access 2000 query problem - Help!

        nope. That's what grouping by the EmployeeID does.

        Comment

        • tehswinstead@gmail.com

          #5
          Re: Access 2000 query problem - Help!


          pietlinden@hotm ail.com wrote:
          [color=blue]
          > nope. That's what grouping by the EmployeeID does.[/color]

          Great stuff. I look forward to trying it on Monday, thanks for your
          help!

          Comment

          Working...