markbabcock
Programmer
I have a SQL Question I was wondering if anyone can help me with.
I have two tables that have the following structure:
table1
+--------+-----------------------+
|ID1 (pk)| subject |
+--------+-----------------------+
| 1 | math |
+--------+-----------------------+
| 2 |history |
+--------+-----------------------+
| 3 |biology |
+--------+-----------------------+
table2
+---------+-----------+---------+-----------------------+
|ID2 (PK) | ID1 (FK) |SendTO | Datetime |
+---------+-----------+---------+-----------------------+
| 1 | 1 | mark | 10/25/2003 14:23:00 |
+---------+-----------+---------+-----------------------+
| 2 | 1 | robin | 10/26/2003 12:03:00 |
+---------+-----------+---------+-----------------------+
| 3 | 2 | mark | 10/25/2003 14:44:00 |
+---------+-----------+---------+-----------------------+
| 4 | 3 | robin | 10/26/2003 08:34:00 |
+---------+-----------+---------+-----------------------+
table1.ID1 is PK for that table
table2.ID1 is FK
table2.ID2 is PK
I want to get the subject and who it was sent to from table two. However, I need to only retreive one person per FK in table2 based on the most recent entry.
for example: if I query mark I should only see that he has histrory. if I query robin I want to see math and biology.
Can anyone please help me with this? Is my table structure off? I have checked the rules of normalization and it seems to be in 3NF.
I have been trying every query i can think of and am stuck. I appreciate the help
I have two tables that have the following structure:
table1
+--------+-----------------------+
|ID1 (pk)| subject |
+--------+-----------------------+
| 1 | math |
+--------+-----------------------+
| 2 |history |
+--------+-----------------------+
| 3 |biology |
+--------+-----------------------+
table2
+---------+-----------+---------+-----------------------+
|ID2 (PK) | ID1 (FK) |SendTO | Datetime |
+---------+-----------+---------+-----------------------+
| 1 | 1 | mark | 10/25/2003 14:23:00 |
+---------+-----------+---------+-----------------------+
| 2 | 1 | robin | 10/26/2003 12:03:00 |
+---------+-----------+---------+-----------------------+
| 3 | 2 | mark | 10/25/2003 14:44:00 |
+---------+-----------+---------+-----------------------+
| 4 | 3 | robin | 10/26/2003 08:34:00 |
+---------+-----------+---------+-----------------------+
table1.ID1 is PK for that table
table2.ID1 is FK
table2.ID2 is PK
I want to get the subject and who it was sent to from table two. However, I need to only retreive one person per FK in table2 based on the most recent entry.
for example: if I query mark I should only see that he has histrory. if I query robin I want to see math and biology.
Can anyone please help me with this? Is my table structure off? I have checked the rules of normalization and it seems to be in 3NF.
I have been trying every query i can think of and am stuck. I appreciate the help