Results 1 to 5 of 5
  1. #1
    m0use is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    3

    can't figure out what i'm doing wrong


    OK, so this should be simple. But nothing I'm trying seems to be working. Three tables related to the problem.

    Employee(PIN, firstName, lastName)
    Late(ID, PIN, lateDate)
    Sick(ID, PIN, sickDate)

    All I want as the output is

    Employee.Pin, Total Number of Times Late, Total Number of sick days


    For some reason, the results for column 2 and 3 are always identical; Both fields are the higher of whichever column would be, if the answers were correct.

  2. #2
    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,725
    What have you tried?

  3. #3
    m0use is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    3
    SELECT Employee.PIN, Count(Sick.PIN) AS SickBookoffs, Count(Late.PIN) AS LateBookoffs
    FROM Employee INNER JOIN Sick ON Employee.PIN = Sick.PIN INNER JOIN Late ON Employee.PIN = Late.PIN
    GROUP BY Employee.PIN;



    this is the most recent code i have

  4. #4
    m0use is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    3
    also i've tried with LEFT and RIGHT JOINS instead, they don't seem to make a difference

  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,725
    I think you need 2 queries 1 for Sick and 1 for Late. Or a sub query.
    But you could use a UNION query such as

    Code:
    SELECT Employee.EmpId, Count(EmployeeDaysLate.DateLate) AS CountOfDateLate,""
    FROM Employee INNER JOIN EmployeeDaysLate ON Employee.EmpId = EmployeeDaysLate.EmployeeId
    GROUP BY Employee.EmpId
    
    UNION
    
    SELECT Employee.EmpId,"",Count(EmployeeDaysSick.DateSick) AS CountOfDateSick
    FROM Employee INNER JOIN EmployeeDaysSick ON Employee.EmpId = EmployeeDaysSick.EmployeeId
    GROUP BY Employee.EmpId
    Union queries require the same number of fields in each Select statement.
    The empty field "" is used to have 3 fields (syntactically) in each Select.

    Good luck


    There is subquery info here http://allenbrowne.com/subquery-01.html

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

Similar Threads

  1. Need a query to figure all possible combinations
    By julestrip in forum Queries
    Replies: 1
    Last Post: 05-27-2011, 07:23 AM
  2. Cannot Figure this query out
    By ryan1313 in forum Queries
    Replies: 6
    Last Post: 08-13-2010, 12:54 PM
  3. Replies: 2
    Last Post: 07-15-2010, 10:26 AM
  4. Easy question...so why can't I figure it out?
    By bdrago527 in forum Access
    Replies: 1
    Last Post: 10-02-2008, 02:40 PM
  5. Can't Figure It Out!!
    By jdohio5 in forum Database Design
    Replies: 1
    Last Post: 05-04-2006, 06:49 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