Results 1 to 7 of 7
  1. #1
    frobro390 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    6

    Returning multiple records Isn't what I need

    Hi everyone,

    I am very new to Access and could certainly use a class on some of the more complex stuff, like SQL... I've got a database that I am using to track clients who come and go from the facility. I've got two tables, a Client_Info table and a Client_Log table. Client info keeps track of all current residents, the log table is where all the time entries are kept.

    I want to run a query that will allow me to find out everyone who is currently logged out, and where they are logged out to. The Client_Info table is as follows:

    Client_ID | Prefix | First_Name | Middle_Initial | Last_Initial | On_Campus | Current_Resident

    Client_Log:

    Log_ID | Client_ID | Destination | Purpose | Event_Time | Event_Date

    I put a query together that checks the On_Campus field, and Current_Resident fields and combines data from both tables, and I am almost getting the results I need. Unfortunately I am getting each and every event for each person If they are currently off campus. I only want the most current event in the client log.

    Does anyone have any possible solutions?

    Thank you in advance, and please forgive my lack of etiquette, this is my first post.



    Anthony

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you described you situation very clearly.

    you need a sub query to find out the most current event for each person, e.g. select client_id, max(datetime) from client_log group by client_id.

    then join to client_info to get other info.

  3. #3
    frobro390 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    6
    Thank you Weekend00, so I think I understand what you are saying. I unfortunately don't understand much SQL, but obviously if this is something I want to pursue I should start to study up. I'll post my results.

  4. #4
    frobro390 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    6
    Talk about feeling stupid... So here is the query as is, where would I apply said sub-query, and... how?


    SELECT Client_Information.Client_ID, Client_Information.First_Name, Client_Information.Last_Name, Client_Log.Destination, Client_Log.Purpose, Client_Log.Event_Time, Client_Log.Event_Date
    FROM Client_Information INNER JOIN Client_Log ON Client_Information.Client_ID = Client_Log.Client_ID
    WHERE (((Client_Information.On_Campus)=False) AND ((Client_Information.Current_Resident)=True));

  5. #5
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    Have done plenty like this but some info in your post I find confusing. Fundamentally the info is found in the log table. (in most designs) One makes the query on the log table. But because the human doesn't know who is client ID 323 (I made that up)...you then join to the client table to provide the human name. Traditionally the client table serves no other role than to provide the human name to the record set that the log table query made.

    But in your case you say you are making a query on fields in the client table - and so that is confusing.

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    create a query named "lastestEvent":

    SELECT client_log.client_id, Max([event_date]+[event_time]) AS eventDT
    FROM client_log
    GROUP BY client_log.client_id;

    create second query to get result:

    SELECT Client_infomation.*, client_log.*
    FROM (latestEvent INNER JOIN client_log ON (format(latestEvent.eventDT,"hhmmss")=format(clien t_log.event_time,"hhmmss")) AND (latestEvent.client_id=client_log.client_id) AND (int(latestEvent.eventDT)=client_log.event_date)) INNER JOIN Client_infomation ON client_log.client_id=Client_infomation.client_id
    WHERE (((Client_infomation.on_campus)=False) AND ((Client_infomation.current_resident)=True));

    It looks something complicated. can may it easier by adding more sub query, but since it works, it's fine.

  7. #7
    frobro390 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    6
    Worked like a charm, thank you very much for your time and effort. Certainly saved my bacon

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

Similar Threads

  1. Add Multiple Records on One Form
    By William McKinley in forum Forms
    Replies: 7
    Last Post: 08-18-2010, 09:31 AM
  2. Combo box returning only about 1000 records
    By cjbuechler in forum Forms
    Replies: 12
    Last Post: 06-30-2010, 08:27 AM
  3. Multiple records with same name BUT..
    By initiator in forum Access
    Replies: 2
    Last Post: 04-11-2010, 12:28 PM
  4. Replies: 1
    Last Post: 12-10-2009, 08:41 PM
  5. Replies: 0
    Last Post: 08-04-2009, 09:14 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