Get maximum from two tables sql

I am making an electronic voting website and have two tables on for vote and the other for candidates I want to get the maximum number of votes for each candidate and I need to produce the result for each candiate like: candidate name: number of votes

My tables looks like:

candidate:Id,name
vote:Id,candidateID,numberofvote

and here is my query

SELECT Vote.Id, 
 Vote.NumberOfvote, 
 Vote.CandidateID, 
 Candidate.Name 
FROM Vote 
INNER JOIN Candidate 
 ON Vote.CandidateID = Candidate.Id

Can anyone help me with this?

Upvotes: 0

Views: 69

Answers (1)

SapManTM
SapManTM

Reputation: 136

I'm not sure I fully understood what is you problem, but anyway you need to use Max() and GROUP BY. something like this:

 SELECT Candidate.Name, Max(Vote.NumberOfvote) 
 FROM Vote INNER JOIN Candidate 
 ON Vote.CandidateID = Candidate.Id 
 GROUP BY Candidate.Name

Upvotes: 1

Related Questions