question

palum avatar image
palum asked

tsql group by join

Have 2 tables TableA StudentID MeetingID TeacherID Date 001 1002581 1056 10-12-2012 001 1006789 1056 10-13-2012 001 1006754 1058 10-13-1012 Have one more table B StudentID MeetingID TeacherID Date Value 001 1002581 1056 10-12-201 15 001 1002856 1056 10-20-2012 21 The conditions are max(date) of a particular student teacher meeting from table A matches the max(date) of the same student teacher meeting in table B with the value. I would like to see the resultset as something like StudentID MeetingID TeacherID Date Value 001 1006789 1056 10-20-2012 21 How can i achieve the above resultset
sql-server-2008tsqljoins
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Forgive me, but the MAX(Date) in TableA won't ever match the MAX(Date) with TableB with the given data. Is there another row in TableB that we are not seeing? Or is that selection criteria need to be different? If I am misunderstanding, please feel free to let me know.
0 Likes 0 ·
For the student teacher combination from table A ...i need the max(date) and value of the same studentnt teacher combination from table B
0 Likes 0 ·

1 Answer

· Write an Answer
Grant Fritchey avatar image
Grant Fritchey answered
It sounds a lot like the versioned data I've worked with before. [I wrote up an article][1] using various methods to retrieve the data. Check this out. I'm sure one of them will meet the requirements you're looking for. [1]: http://www.simple-talk.com/sql/database-administration/sql-strategies-for-versioned-data/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.