Query that shows names and vote counting in MySQL

0

I am starting to work with MySQL in a survey and I need to print the different names that I have in my table CANDIDATE and make a count of the votes that each one has in the table VOTES , the tables are referenced by the CANDIDATE_ID.

I'm doing an INNER JOIN but I can not print both at the same time. If I do the counting does not show all the names and if I show the names I do not know how to show how many votes you have.

    
asked by Keren 28.02.2018 в 19:07
source

1 answer

0

Your query should be something like

SELECT C.nombre, COUNT(V.voto) AS votos 
FROM CANDIDATO C INNER JOIN VOTOS V ON C.id=V.id_candidato
GROUP BY C.id

It is important to add the GROUP BY , to differentiate the different candidates

    
answered by 28.02.2018 / 19:14
source