Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Records with matching field

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
GB
I'm trying to count the number of comments made by a specific user.

EG
SELECT COUNT(UserID) AS CommentNumber
FROM UserComments

Presently of course all I get is the total number of comments and not the number of comments made by each user. The UserID starts from 1 and rises.

tia
Struth
 
SELECT COUNT(UserID) AS CommentNumber
FROM UserComments
WHERE UserID = 1 'the user u wish to count for
 
Thanks, but what I'm after is an output like this:

USER | NO OF COMMENTS
-----------------------
User1 | 6
-----------------------
User2 | 2
-----------------------
User3 | 4
-----------------------

Etc

Struth
 
select user_id, count(comment_no)
from UserComments
group by user_id
 
Thanks but this gives me an error - too few parameters

So I tried this

SELECT UserID, COUNT(*) AS CommentNumber
FROM UserComments
GROUP BY UserID;

No errors as such but it still didn't come up with what I wanted - it just came up with one UserID CommentNumber repeated.

Any other ideas?

tia
Struth
 
This last one actually worked ... problem was somewhere else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top