In vs = Subquery Operators

Viewed 23

On row three, When I changed c.id = to c.id IN, MYSQL indicated error. I wonder why is that as they are both operators that doing comparing/checking if exists in?

Select distinct c.Name As Name
from Candidate c
where c.id = (Select CandidateId 
              from Vote
              Group by CandidateId  
              order by count(CandidateId) desc
              limit 1)
1 Answers

Either change that = to a IN operator (OR) use a JOIN statement

Select distinct c.Name As Name
from Candidate c
where c.id in (Select CandidateId 
              from Vote
              Group by CandidateId  
              order by count(CandidateId) desc
              limit 1)
Related