Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-11-09 : 08:18:19
|
| farid writes "i have 2 tables t_students student_id = 1student_name = Monicat_coursescourse_id = 1student_id = 1course_name= wordcourse_id = 2 student_id = 1course_name= excelwhen i search for exapmle using like "like student name" i want todisplay one record containing student_name and the last course like the following:student name course name course_idMonica excel 2 but i used max fuction i get student name course name course_id Monica word 2 beacuse the letter w is after letter ePlease help me and thank you for all.Regards,--------------------------------------------------------------------------------" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-09 : 08:36:52
|
[code]select s.student_name, c.course_name, c.course_idfrom t_students s inner join t_courses c on s.student_id = c.student_id and c.course_id = (select max(course_id) from t_courses x where x.student_id = s.student_id)[/code] KH |
 |
|
|
|
|
|