Hi Friends I wan to Display top 3 results from my database values...i have mentioned the table below can any one tell me how to execute ......
My table is:
NAME Maths English
xxx 98 75
yyy 100 91
eee 94 88
aaa 100 100
fff 78 56
rrr 56 95
my expected answer is:
NAME Maths
yyy 100
aaa 100
xxx 98
Can anyone help me out...
Loading


Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 10:01 PM EDT
You can do like this
SELECT TOP 3 NAME,Maths FROM YourTable ORDER BY Maths desc
Regards,
Iftikar
selva kumarRank #2,987 · 483 reputationPosted Jul 12, 2013, 10:52 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 12, 2013, 10:54 PM EDT
select top 3 NAME,Maths from tabelname order by Maths desc
or if you want top 3 math results. then you can use this
SELECT NAME,Maths from
(SELECT *,DENSE_RANK() over( order by Maths desc) SRANK from yourtablename) as MATH
Where SRANK <=3
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 10:54 PM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 11:10 PM EDT
Regards,
Iftikar
selva kumarRank #2,987 · 483 reputationPosted Jul 12, 2013, 11:22 PM EDT
I Have used ur query but i did't get correct answer...Can u check and tell me exact query....
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 11:28 PM EDT
select top 3 Name,cast(Maths as int) from report order by cast(Maths as int) desc
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 12, 2013, 11:31 PM EDT
SELECT TOP 3 NAME,Maths FROM report ORDER BY cast(Maths as int) desc
selva kumarRank #2,987 · 483 reputationPosted Jul 13, 2013, 12:24 AM EDT
selva kumarRank #2,987 · 483 reputationPosted Jul 13, 2013, 12:25 AM EDT
Dilshad AliRank #1,926 · 762 reputationPosted Jul 13, 2013, 12:32 AM EDT
selva kumarRank #2,987 · 483 reputationPosted Jul 13, 2013, 1:30 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 13, 2013, 3:02 AM EDT
Select Name,maths as Marks from yourtable
Regards,
Iftikar