Results 1 to 7 of 7
  1. #1
    BICAP is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2015
    Posts
    2

    Selecting certain records in a one to many relationship on alternate criteria

    If I have these tables in a shuttle service database:

    EventID CreateDate FirstDepart LastDelivery
    1 1/1/10 11:31 AM 1/1/10 11:32 AM 1/1/10 12:25 PM
    2 1/1/10 11:36 AM 1/1/10 11:37 AM 1/1/10 12:02 PM
    3 1/1/10 11:54 AM 1/1/10 11:56 AM 1/1/10 1:04 PM
    EventID
    RecID
    ShuttleID
    Agency
    Depart
    Arrive
    1
    105043
    Bus4
    SPEEDY 1/1/2010 11:37:55 AM 1/1/2010 11:44:55 AM
    1
    105044
    Van4
    SPEEDY 1/1/2010 11:37:36 AM 1/1/2010 11:45:10 AM
    1
    105045
    Van6
    QUICK 1/1/2010 11:38:23 AM 1/1/2010 11:45:02 AM
    1
    105046
    Van9
    SPEEDY 1/1/2010 11:38:10 AM 1/1/2010 12:02:59 PM
    1
    105047
    Truck4
    SPEEDY 1/1/2010 11:37:44 AM 1/1/2010 11:58:47 AM
    1
    105048
    Car4
    QUICK 1/1/2010 11:37:22 AM 1/1/2010 11:44:58 AM
    2
    105049
    Bus2
    SPEEDY 1/1/2010 11:58:42 AM 1/1/2010 12:29:38 PM
    2
    105050
    Van10
    SPEEDY 1/1/2010 11:56:07 AM 1/1/2010 12:28:46 PM
    2
    105051
    Van2
    SPEEDY 1/1/2010 11:59:21 AM 1/1/2010 12:54:44 PM
    2
    105052
    Van3
    FAST 1/1/2010 11:59:23 AM 1/1/2010 12:19:37 PM
    2
    105053
    Van8
    SPEEDY 1/1/2010 11:56:38 AM 1/1/2010 12:48:30 PM
    2
    105054
    Truck2
    FAST 1/1/2010 11:58:55 AM 1/1/2010 12:31:01 PM
    2
    105055
    Car12
    SPEEDY 1/1/2010 11:56:29 AM 1/1/2010 1:04:01 PM
    2
    105056
    Car3
    QUICK 1/1/2010 12:02:56 PM 1/1/2010 12:56:59 PM
    3
    105057
    Truck6
    SPEEDY 1/1/2010 1:24:03 PM 1/1/2010 1:44:50 PM
    3
    105058
    Car66
    QUICK 1/1/2010 1:24:31 PM 1/1/2010 2:29:26 PM
    3
    105059
    Car5
    QUICK 1/1/2010 2:30:50 PM 1/1/2010 2:31:35 PM
    Can anyone provide insight on the best way to query for each event and get the first to depart and/or the first to arrive and or the last to arrive for a specific service? I've tried a number of combinations and it iss difficult not to get multiple results for some events. It would be great if I could ignore records with ties but that would be extra credit.

    I can get the first, last, etc shuttle, but I want to ask what was the first QUICK shuttle to depart for each event and get:

    EventID CreateDate RecID ShuttleID Depart
    1 1/1/10 11:31 AM 105048 Car4 1/1/2010 11:37:22 AM
    2 1/1/10 11:36 AM 105056 Car3 1/1/2010 12:02:56 PM
    3 1/1/10 11:54 AM 105058 Car66 1/1/2010 1:24:31 PM

    I'd also like to be able to ask what was the first van to depart and get:

    EventID CreateDate RecID ShuttleID Agency Depart
    1 1/1/10 11:31 AM 105044 Van4 SPEEDY 1/1/2010 11:37:22 AM
    2 1/1/10 11:36 AM 105050 Van10 SPEEDY 1/1/2010 12:02:56 PM
    3 1/1/10 11:54 AM



    (Or no record for event 3 if there was no van)

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I can get the first, last, etc shuttle, but I want to ask what was the first QUICK shuttle to depart for each event and get:
    Have you tried using the Max() and the Min() functions with the Date column? Maybe you can use one of those functions via a Totals query and also add some Criteria.

  3. #3
    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,726
    What exactly is an Event? I don't see the link between EventID and any other field--so why are here multiples of Event 1....?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by orange View Post
    What exactly is an Event? I don't see the link between EventID and any other field--so why are here multiples of Event 1....?
    I was wondering the same thing. Having this column included in a query that performs an aggregate calc may produce undesirable results.

  5. #5
    BICAP is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2015
    Posts
    2
    Each event has multiple shuttles assigned (one to many). I can get the first or last using min/max for each event, but if you try and get the first van or for the first [van or truck] I get multiple results per event as if I'm getting the min of that record.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I get multiple results per event as if I'm getting the min of that record.
    You might want to build more than one query. In a new query, you might be able to employ an aggregate calc on one column, while only including one or two other columns. Adding and or removing columns may have an affect on your calcs. Keep in mind that you can nest queries as sub-queries.

  7. #7
    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,726
    OK, so what exactly is an event? Can you give us an example so we understand?


    Sounds like you may have:


    Customers
    Vehicles
    Events
    Shuttles

    If so, you might want to describe in plain English how these inter-relate and apply to what you are trying to do.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2015, 02:11 PM
  2. Selecting records with matching criteria
    By Daryl2106 in forum Access
    Replies: 2
    Last Post: 09-07-2013, 03:57 AM
  3. Replies: 9
    Last Post: 07-22-2013, 03:37 PM
  4. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  5. Selecting records based on criteria from user input
    By shabbaranks in forum Programming
    Replies: 1
    Last Post: 01-04-2012, 09:06 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