I have a SQL problem. I need to join 3 tables. I have a tables a users, with a user_id primary key. I have a table of locations which references the user table using the user_id. I have a table of samples which references the location table with a location_id key. It looks like as follows...
USERS
.
.. LOCATIONS
.
.. SAMPLES
I need to join these three tables, BUT I need to get the latest sample in the SAMPLE Table. This is my problem. I can join the three tables, but how can I get the latest sample for each location, it should look like...
USER_ID LOCATION_ID SAMPLE_DATE
1 1 2/2/04
1 2 3/2/04
2 4 2/2/04
2 7 5/2/04
As you can see you can repeat the user_id, but you can't repeat the location_id. I need the last sample taken for each location. If anyone can help me that would be great. Thank You.
USERS
.
.. LOCATIONS
.
.. SAMPLES
I need to join these three tables, BUT I need to get the latest sample in the SAMPLE Table. This is my problem. I can join the three tables, but how can I get the latest sample for each location, it should look like...
USER_ID LOCATION_ID SAMPLE_DATE
1 1 2/2/04
1 2 3/2/04
2 4 2/2/04
2 7 5/2/04
As you can see you can repeat the user_id, but you can't repeat the location_id. I need the last sample taken for each location. If anyone can help me that would be great. Thank You.