Results 1 to 3 of 3
  1. #1
    GabyArco is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    3

    Question Match Dates from two tables

    Hi,

    I have two tables, one with sample dates and corresponding temperature values, and a second table with height values and the dates when these height values were taken:

    Table_1_Samples
    Sample_Date Temperature
    3/3/13 20
    3/6/13 18
    3/15/13 21
    3/20/13 20
    4/1/13 16
    4/7/13 20
    4/18/13 17


    Table_2_Heights
    Height_Date Height
    3/1/13 15
    3/7/13 20
    3/19/13 13
    4/15/13 17



    I need to know, for each sample date and temperature, when was the last height measurement taken and what was that height. The output should look something like this:


    Sample_Date Temperature Last_Height_Date Height
    3/3/13 20 ? ?
    3/6/13 18 ? ?
    3/15/13 21 ? ?
    3/20/13 20 ? ?
    4/1/13 16 ? ?
    4/7/13 20 ? ?
    4/18/13 17 ? ?
    So, for the first sample date (3/3/13), the last height date should be 3/1/13 and the height should be "15", for the second to last sample date (4/7/13), the last height date should be "3/19/13" and the corresponding height should be "13".

    What is the best way to query my tables to generate these two new columns with the right information? All and any help is greatly appreciated. I've been trying to solve this on my own, and I can't figure it out.
    Thanks!!

  2. #2
    GabyArco is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    3
    Using the SQL expression

    SELECT Sample_Date.Sample_Date, Sample_Date.Temperature, Height.Height_Date, Height.Height
    FROM Sample_Date, Height
    WHERE Height.Height_Date <= Sample_Date.Sample_Date

    I get

    Sample_Date Temperature Height_Date Height
    3/3/2013 20 3/1/2013 15
    3/6/2013 18 3/1/2013 15
    3/15/2013 21 3/1/2013 15
    3/15/2013 21 3/7/2013 20
    3/20/2013 20 3/1/2013 15
    3/20/2013 20 3/7/2013 20
    3/20/2013 20 3/19/2013 13
    4/1/2013 16 3/1/2013 15
    4/1/2013 16 3/7/2013 20
    4/1/2013 16 3/19/2013 13
    4/7/2013 20 3/1/2013 15
    4/7/2013 20 3/7/2013 20
    4/7/2013 20 3/19/2013 13
    4/18/2013 17 3/1/2013 15
    4/18/2013 17 3/7/2013 20
    4/18/2013 17 3/19/2013 13
    4/18/2013 17 4/15/2013 17




    I would like to only get one record per sample date, i.e. for every sample date *only* the closest dated height. Thanks!

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Just by looking I would say your table are not related as they should be.
    If they are not related I cannot see a way to filter them.
    To put them together you have to have something in common between the 2 records.
    Can you show us a picture of your tables?

    Dale

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

Similar Threads

  1. Replies: 3
    Last Post: 05-20-2013, 04:18 PM
  2. tables and dates
    By bigmac in forum Access
    Replies: 7
    Last Post: 02-24-2012, 06:39 AM
  3. Replies: 14
    Last Post: 02-12-2012, 10:14 AM
  4. Cannot match same data in different tables
    By jitendrakalyan in forum Queries
    Replies: 3
    Last Post: 11-22-2010, 12:26 PM
  5. Replies: 1
    Last Post: 06-20-2007, 07:26 PM

Tags for this Thread

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