1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

MS Access

Discussion in 'Business Applications' started by Jeff Klein, Jan 1, 2002.

Thread Status:
Not open for further replies.
Advertisement
  1. Jeff Klein

    Jeff Klein Thread Starter

    Joined:
    May 28, 2001
    Messages:
    5
    I need to create a query that shows the last state that a employee has visited. The entire row with all columns must show in the query.

    The original table columns: Name, Date, State, Reason, and Expense.

    The resulting information is to be used in a linked word document.
    (this I can do)

    Can anyone help...point me in some direction...

    Thanks, Jeff
     
  2. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    Is there a field in any of your tables that has the last state visited information? If there is a new recrd created each time they visit a state than you could set the filter to the last record for that employee.
     
  3. THoey

    THoey

    Joined:
    Feb 12, 2001
    Messages:
    3,420
    SELECT MyTable.Name, MyTable.State, MAX(MyTable.Date)
    FROM MyTable
    GROUP BY MyTable.Name, MyTable.State

    This should pull out a listing of all Employees and the last state they visited...
     
  4. downwitchyobadself

    downwitchyobadself

    Joined:
    Oct 13, 2000
    Messages:
    941
    Hi. Don't know if you worked this out yet, but I don't see the "right" answer, so I'll pretend you haven't... :)

    The thing is, you cannot get from the same table both the maximum date and the related state as th suggests in a single query; what you have to do is build two queries.

    Query 1 is an aggregate query, as th suggests, but pulls only name (terrible field names, by the way--read here to find out why) and max date. Otherwise, if you group by state as well, you'll get the last date that each name visited each state.

    Save the first query with whatever name you like. I'm pretending it's called qryLastVisitDte.

    Query 2 includes the original table and qryLastVisitDte. You link the Name and the MaxOfDate fields in qryLastVisitDte to the related fields in your table, and that will pull the state related to each date and name. Of course, this will only work as long as no one visited more than one state in a day...
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/63755

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice