You must Sign In to post a response.
  • Category: SQL Server

    Give Detail of Student who stood first in each class

    Table1:
    student (gr_no,name,gender,address,city,class)

    Table2:
    marks(gr_no,sub1,sub2,sub3,total,per)

    Query:
    Give Detail of Student who stood first in each class
  • #764564
    simple query to fire
    Select a.gr_no, a.name, a.gender, a.address, a.city, a.class, MAX(b.per) from student a, marks b
    where a.gr_no = b.gr_no

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764569
    i want result classwise,first from each class
    like
    SELECT s.Class ,MAX(m.Per)
    from
    Student s
    INNER JOIN
    Marks m
    ON s.GRNO=m.GRNO
    group by s.Class

    but in above details are not displayed

  • #764573
    Hello Alex,

    You can use inner join between two tables and perform sorting.
    The students who got highest marks will be automatically arranged on top in dataset.

    Identify the classes individually by providing filter about the datagridview, by applying condition of class in query.

    Still you face any problem, you are free to let us know.

    Regards,
    Dhiraj C. Solanki

  • #764592
    Hi,

    Use below sample


    select s.class, Max(m.per) as Percentage
    from student s,
    Marks m
    where s.gr_no=m.gr_no

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764593

    Hi alex,
    Try this:
    select distinct s.Class, m.Per as Percentage, s.name, s.gender, s.address, s.city
    from Student s INNER JOIN Marks m ON s.gr_no = m.gr_no
    where m.Per in (select MAX(Per) from Marks m1, Student s1 where m1.gr_no=s1.gr_no group by s1.Class)
    group by s.Class,m.per, s.name, s.gender, s.address, s.city
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764598
    thank you shashikant gurav
    its working


Sign In to post your comments