Sunday, August 8, 2010

Fetch out More than 3 entries for one name and class column

Suppose you want to Fetch out More than 3 entries in a class with the same name of student, than you can use following query:
Here Id is table's primary key.

Select * from Table1 t6
where Id < (select MAX(Id) from (Select * from Table1 t4
where Id < (select max(Id) from (Select * from Table1 t2
where Id < (select Max(Id)from Table1 t1 where t1.name = t2.name and t1.class = t2.class)) t3 where t4.class= t3.class and t4.name = t3.name )) t5 where t6.class= t5.class and t6.name = t5.name )
order by t6.name desc



Thanks.

No comments:

Post a Comment