Results 1 to 3 of 3
  1. #1
    barbj1969 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    2

    Select query


    Hi,

    I have a table where I need to select the record where the booking end date for a Site does not have a booking following on. For example the first record for site AB020/E that ends on 22/03/2015 has a follow on booking in record 2 (same site - booking start date is previous booking end date plus 1). However record 2 for that site does not have a follow on booking.

    Therefore out of this table I would want to select record 2, record 4, record 8, record 9 and record 10.

    Can anyone help me with how I would write this please? Thanks for your time.

    SITE BOOKING START DATE BOOKING END DATE CAMPAIGN ID CAMPAIGN NAME
    AB020/E 24/03/2014 22/03/2015 5339 ABC PTY LTD
    AB020/E 23/03/2015 20/03/2016 5339 ABC PTY LTD
    AB020/W 16/06/2014 14/06/2015 5531 BCD EXPRESS
    AB020/W 15/06/2015 12/06/2016 5531 BCD EXPRESS
    AB030/E 19/05/2014 05/10/2014 4602 FRED BLOGGS
    AB030/E 06/10/2014 02/11/2014 4602 FRED BLOGGS
    AB030/E 03/11/2014 17/05/2015 4602 FRED BLOGGS
    AB030/E 18/05/2015 15/05/2016 5900 FILLER
    AB030/W 16/06/2014 14/06/2015 4748 SMITHS CAFE
    AB040/E 09/09/2013 07/09/2014 4214 MAC'S DINER

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You didn't give table or field names, sooooo..

    I created a table "CAMPAIGN" (I really hate shouting) with the headings from the table above in proper case.
    I created Query2 to get the max dates by site.
    Code:
    SELECT Campaign.Site, Max(Campaign.BookingEndDate) AS MaxOfBookingEndDate
    FROM Campaign
    GROUP BY Campaign.Site;
    Then I created another query (Query4) adding Query2 and table "Campaign"
    Code:
    SELECT Campaign.Site, Campaign.bookingStateDate, Campaign.BookingEndDate, Campaign.CampaignID, Campaign.CampaignName
    FROM Query2 INNER JOIN Campaign ON (Query2.Site = Campaign.Site) AND (Query2.MaxOfBookingEndDate = Campaign.BookingEndDate);
    This is only one method..

    Of course it would be easier if the table was normalized...

  3. #3
    barbj1969 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    2
    Thank you so much for your reply. I used to do a fair bit in Access but haven't done anything for about 9 years. Will have a play with that and also normalise the table. It was originally an excel spreadsheet but I didn't know how to write it in excel and thought I would have better luck with Access.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-14-2014, 01:17 PM
  2. Replies: 1
    Last Post: 05-02-2014, 09:29 AM
  3. Replies: 5
    Last Post: 05-01-2013, 11:39 AM
  4. Replies: 7
    Last Post: 05-02-2012, 08:04 AM
  5. Replies: 2
    Last Post: 01-31-2011, 08:31 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