Monday, 26 August 2013

Sql script to get values for two tables combined

Sql script to get values for two tables combined

pI have two tables like this:/p precode Table1 ________ StudentNumbers
ExamType 1234 1 2343 2 3345 5 3454 1 5465 2 ... Table2 ________
StudentNumbers ExamType ExamDate School Area 1234 1 0825 warren ny 1234 1
0829 north nj 1233 2 0921 north nj 2343 1 0922 warren ny 2343 1 0925 north
ny ... /code/pre pI need to find out each students maximum ExamDate from
the Table2 by using data from Table1 for particular ExamType. I have come
up with this so far but this seems incorrect:/p precodeSelect
t1.StudentNumbers, t1.ExamType, max(t1.ExamDate), t1.School, t1.Area from
Table1 as t1 Join Table2 as tl t1.StudentNumbers = t2.StudentNumbers where
t2.ExamType = 1 /code/pre pIt should basically return back:/p
precodeStudentNumbers ExamType ExamDate School Area 1234 1 0829 north nj
2343 1 0925 north ny /code/pre

No comments:

Post a Comment