Results 1 to 6 of 6
  1. #1
    Phoenyxsgirl is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Location
    Joplin, MO
    Posts
    48

    Confounded Query Results - Grouping help


    I am running a query to find where an employee worked before leaving the company. I can get the last day they worked which is tied to one specific department using "First" as the grouping sort but I cannot pull the department. When I try to add this information to the query, it brings up all departments.

    How do I keep this limited to just the last department they worked in?

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Sort your query by Date Descending and then:
    Click View -> SQL View.
    Right after the word Select type in Top 1
    So your Query will look something like this:
    Code:
     
    SELECT top 1 [TableName].ID, [TableName].[Employee_Name], [TableName].[Department], [TableName].[DateField]
    FROM [TableName]
    WHERE [TableName].[Employee_Name] = "Some Name"
    ORDER BY [TableName].[DateField] DESC;
    Hope this helps!!
    Last edited by Robeen; 11-10-2011 at 12:30 PM. Reason: Omission.

  3. #3
    Phoenyxsgirl is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Location
    Joplin, MO
    Posts
    48
    When I do this, it takes to top most record only. Not from each employee but from the whole query.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You said 'an employee'.
    I took that to mean a single employee.

  5. #5
    Phoenyxsgirl is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Location
    Joplin, MO
    Posts
    48
    ahhh sorry i have to pull a list of all employees that have left the company. Each employee has multiple worksites they have been at. I have to pull the very last one they were at which I can only distinguish it from the last day they worked at each site.

    When I pull the query with just the employee and the last day they worked at ANY site, it gives me the right information.

    When I add to the query the name and/or location of the worksite, it then adds in ALL the worksites.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I've been thinking about it . . .

    Here's something you can try:
    A.
    1. Create a query with EmployeeName and WorkDate fields.
    2. Group on EmployeeName and Max on WorkDate.

    B.
    Create another query with EmployeeName, WorkDate and Department.

    C.
    1. Create a third query & add the above two queries A & B - in that order.
    2. Join the WorkDate fields of the two queries.
    3. Right-Click on the Join line and click Properties.
    4. Select 2 [ . . . all fields from left table & matching fields from right . . .].
    5. Add EmployeeName and WorkDate from query A. and Department from query B.

    Does that give you what you need?

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

Similar Threads

  1. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  2. Creating a Grouping query
    By Dev in forum Access
    Replies: 4
    Last Post: 09-02-2010, 06:46 AM
  3. Grouping hours query
    By DMP84 in forum Queries
    Replies: 0
    Last Post: 08-26-2010, 07:15 AM
  4. Grouping query
    By Mphiri in forum Programming
    Replies: 10
    Last Post: 06-15-2010, 08:58 AM
  5. Need help grouping results.
    By cljac in forum Queries
    Replies: 9
    Last Post: 03-24-2010, 10:10 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