x

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, 2012 at 06:22 PM in Default

palum gravatar image

palum
249 25 29 30

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, 2012 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, 2012 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, 2012 at 07:41 PM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
98.1k 19 21 74

(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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1834
x280
x116

asked: Nov 14, 2012 at 06:22 PM

Seen: 622 times

Last Updated: Nov 14, 2012 at 11:41 PM