1. Student Table have:ID, STUDENT_ID, STUDENT_NAME, YEAR, CLASS, ROLL
Find each student name, the last year in database, class name
Find each student name, the last year in database, class name
- ID, STUDENT_ID STUDENT_NAME YEAR CLASS ROLL
- 1 2 A 2010 I 5
- 2 2 A 2012 III 5
- 3 5 C 2010 IX 5
- 4 2 A 2014 V 5
- 5 7 E 2018 IX 5
- 6 2 A 2016 VII 5
Query:
- Select ST1.ID, ST1.STUDENT_ID, ST1.STUDENT_NAME, ST1.YEAR, ST1.CLASS, ROLL from STUDENT ST1 INNER JOIN
- (
- SELECT STUDENT_ID , MAX(YEAR) MAXYEAR from STUDENT GROUP BY STUDENT_ID
- )
- ST2 on ST1.STUDENT_ID = ST2.STUDENT_ID AND ST1.ID = ST2.ID
No comments:
Post a Comment