x
login about faq Site discussion (meta-askssc)

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

more ▼

asked Nov 14 '12 at 06:22 PM in Default

palum gravatar image

palum
249 12 22 27

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.

Nov 14 '12 at 07:16 PM JohnM

For the student teacher combination from table A ...i need the max(date) and value of the same studentnt teacher combination from table B

Nov 14 '12 at 11:40 PM palum
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

It sounds a lot like the versioned data I've worked with before. I wrote up an article using various methods to retrieve the data. Check this out. I'm sure one of them will meet the requirements you're looking for.

more ▼

answered Nov 14 '12 at 07:41 PM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
62.2k 12 20 66

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x224
x21

asked: Nov 14 '12 at 06:22 PM

Seen: 245 times

Last Updated: Nov 14 '12 at 11:41 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.