i***@gmail.com
2012-12-14 11:30:02 UTC
I have a table candidate with following columns and data
CandidateId int
CandidateName varchar(100)
NumberofVotes int
CountyId(FK) int
CountyId(int) in table candidate is foreign key from County table. County table has CountyId(int) and CountyName (varchar 100).
I would like to get the candidatename, countyname and numberofvotes by which a candidate is leading in a particular county.
For example in the below example
CandidateId CandidateName NumberofVotes CountyId
1 John 100 1
2 Mary 44 1
3 Tomy 62 1
4 Bill 20 1
In CountyId=1 John is leading by 38 votes from second highest candidate so this query should return me.
John (countyname) 38
CandidateId int
CandidateName varchar(100)
NumberofVotes int
CountyId(FK) int
CountyId(int) in table candidate is foreign key from County table. County table has CountyId(int) and CountyName (varchar 100).
I would like to get the candidatename, countyname and numberofvotes by which a candidate is leading in a particular county.
For example in the below example
CandidateId CandidateName NumberofVotes CountyId
1 John 100 1
2 Mary 44 1
3 Tomy 62 1
4 Bill 20 1
In CountyId=1 John is leading by 38 votes from second highest candidate so this query should return me.
John (countyname) 38