Tuesday 10 July 2012

SQL Query: Select a column where other column value is minimum

Scenario: In our College, a AS level science student need 2 years to finish the course. Each year they need to take admission. So if a student come back so his year entry will be twice.

Solution:
SELECT     STYR_Student_ID, STYR_Enrolled_On, STYR_Year
FROM         STYRstudentYR
where      (STYR_Student_ID = '22293') and STYR_Year=
(select min(STYR_Year) from STYRstudentYR
where      (STYR_Student_ID = '22293'))
ORDER BY STYR_Student_ID, STYR_Year

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home