I didn't read the previous posts. The idea is really similar, but I'm not using a temp table (I probably should). This would be a lot easier on 2005+
SELECT s.*
FROM #student s
JOIN (SELECT 1 priority,'IT' class UNION ALL SELECT
2,'Science' UNION ALL SELECT
3,'Arts' UNION ALL SELECT
4,'Commerce' UNION ALL SELECT
5,'Geography' UNION ALL SELECT
6,class
FROM #student
WHERE class NOT IN( 'IT','Science','Arts','Commerce','Geography')
GROUP BY class) p ON s.class = p.class
JOIN (select rollno, MIN( priority) minpriority
FROM #student s
JOIN (SELECT 1 priority,'IT' class UNION ALL SELECT
2,'Science' UNION ALL SELECT
3,'Arts' UNION ALL SELECT
4,'Commerce' UNION ALL SELECT
5,'Geography' UNION ALL SELECT
6,class
FROM #student WHERE class NOT IN( 'IT','Science','Arts','Commerce','Geography')) p ON s.class = p.class
GROUP BY rollno) o ON s.rollno = o.rollno AND p.priority = o.minpriority