Select top 2 not working on Maximum Record using SQL
-
Issue occrue on select top 2 like this when run the following query then show the following result SELECT u.ElectionDtlID,u.PartyShortNameEng,u.ConstituencyName,u.VotesObtained FROM tblElectionsDetail u where u.ConstituencyName='NA 108' and u.electionyear='2013' and u.VotesObtained > 0 RESULT: ID NameEng Constituency VotesObtained 10864 PPPP NA 108 29883 10865 PMLN NA 108 73789 10866 PTI NA 108 25406 10867 JI NA 108 18270 10868 Ind NA 108 85009 But now i want to get only top result of Maximum VotesObtained Candidate like this : Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='NA 108'; and electionyear='2013'; order by VotesObtained desc Then this issue the following Result OutPut Table: VotesObtained 85009 73789 this is working good and also result show correct but when i want to show max/top 2 recrod but order by asc then it's working correct like this Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='na 108' and electionyear='2013' order by VotesObtained asc the result of the query like this OutPut Table: VotesObtained 0 0 so i wan to get the result like this. VotesObtained 73789 85009 any body can help me ?
-
Issue occrue on select top 2 like this when run the following query then show the following result SELECT u.ElectionDtlID,u.PartyShortNameEng,u.ConstituencyName,u.VotesObtained FROM tblElectionsDetail u where u.ConstituencyName='NA 108' and u.electionyear='2013' and u.VotesObtained > 0 RESULT: ID NameEng Constituency VotesObtained 10864 PPPP NA 108 29883 10865 PMLN NA 108 73789 10866 PTI NA 108 25406 10867 JI NA 108 18270 10868 Ind NA 108 85009 But now i want to get only top result of Maximum VotesObtained Candidate like this : Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='NA 108'; and electionyear='2013'; order by VotesObtained desc Then this issue the following Result OutPut Table: VotesObtained 85009 73789 this is working good and also result show correct but when i want to show max/top 2 recrod but order by asc then it's working correct like this Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='na 108' and electionyear='2013' order by VotesObtained asc the result of the query like this OutPut Table: VotesObtained 0 0 so i wan to get the result like this. VotesObtained 73789 85009 any body can help me ?
-
Issue occrue on select top 2 like this when run the following query then show the following result SELECT u.ElectionDtlID,u.PartyShortNameEng,u.ConstituencyName,u.VotesObtained FROM tblElectionsDetail u where u.ConstituencyName='NA 108' and u.electionyear='2013' and u.VotesObtained > 0 RESULT: ID NameEng Constituency VotesObtained 10864 PPPP NA 108 29883 10865 PMLN NA 108 73789 10866 PTI NA 108 25406 10867 JI NA 108 18270 10868 Ind NA 108 85009 But now i want to get only top result of Maximum VotesObtained Candidate like this : Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='NA 108'; and electionyear='2013'; order by VotesObtained desc Then this issue the following Result OutPut Table: VotesObtained 85009 73789 this is working good and also result show correct but when i want to show max/top 2 recrod but order by asc then it's working correct like this Query: select top 2 VotesObtained from tblElectionsDetail where ConstituencyName='na 108' and electionyear='2013' order by VotesObtained asc the result of the query like this OutPut Table: VotesObtained 0 0 so i wan to get the result like this. VotesObtained 73789 85009 any body can help me ?