Reputation: 824
Hey guys I have a dilemma with one of my SELECTS that I use in mySQL DB.
Firstly this is how it looks :
My select is supposed to extract all the users and count each their prezente , when I use this select instead of taking all my users I get this :
SELECT users1.id,users1.Nume, COUNT(pontaj.prezente)
FROM users1, pontaj
WHERE users1.id = pontaj.id
Upvotes: 0
Views: 61
Reputation: 142298
pontaj.prezente is an INT; perhaps you want SUM(pontaj.prezente) ??
Upvotes: 0
Reputation: 2128
SELECT DISTINCT users1.id, users1.Nume, COUNT(pontaj.prezente) over (partition by users1.id)
FROM users1
INNER JOIN pontaj ON users1.id = pontaj.id
This is an alternative if you don't want to use the GROUP BY
Upvotes: 1
Reputation: 178
I think you should add a group by clause meaning at the end of the SQL add
group by users1.Nume
Upvotes: 1
Reputation: 28741
You need to add a GROUP BY clause to your query. Also replace the old join syntax using WHERE clause with recommended JOIN / ON syntax.
SELECT users1.id,users1.Nume, COUNT(pontaj.prezente)
FROM users1
INNER JOIN pontaj
ON users1.id = pontaj.id
GROUP BY users1.id,users1.Nume
Upvotes: 2