November 7, 2011 at 6:30 am
i have three table
1. student (stuid,name)
2. subject (subid,sname,studid)
3. marks (subid,studentid,marks)
i want the reslut of who as got max marks in each subject
sudentname,max(marks), name
abc,70,nikitha
November 7, 2011 at 6:41 am
Have a look here:
http://www.sql-tutorial.net/SQL-JOIN.asp
for joins and here:
http://msdn.microsoft.com/en-us/library/ms187751.aspx
for the MAX() function.
Both will help you to complete what I'm assuming is your homework.
November 7, 2011 at 6:57 am
SELECT
s2.sname,
m.marks,
s.name
FROM @marks-2 AS m
JOIN @Student AS s ON
s.stuid = m.studentid
JOIN @Subject AS s2 ON
s2.subid = m.subid
WHERE m.marks =
(
SELECT MAX(m2.marks)
FROM @marks-2 AS m2
WHERE m2.subid = m.subid
)
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
November 7, 2011 at 7:22 am
Thanks
i will try it
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply