steelerman99 Posted February 11, 2008 Share Posted February 11, 2008 I'm trying to make a query which would have 2 columns: the first column would be the person's name and the second column would be how many times that person's name appears in the table. How would I go about doing this? I've tried it using "Select name, COUNT(*) FROM...." but that doesn't seem to work. I appreciate your help! Thanks! Link to comment https://forums.phpfreaks.com/topic/90425-count-with-select/ Share on other sites More sharing options...
trq Posted February 11, 2008 Share Posted February 11, 2008 SELECT name, COUNT(name) AS namecount FROM tbl Link to comment https://forums.phpfreaks.com/topic/90425-count-with-select/#findComment-463605 Share on other sites More sharing options...
steelerman99 Posted February 11, 2008 Author Share Posted February 11, 2008 it didn't work... it doesn't seem to like when I add multiple columns with the COUNT() function. i'm doing this sql through PHP, then displaying the results in a table on the page. Link to comment https://forums.phpfreaks.com/topic/90425-count-with-select/#findComment-463630 Share on other sites More sharing options...
steelerman99 Posted February 11, 2008 Author Share Posted February 11, 2008 Got it. I needed to add a "group by" clause or it wouldn't work. Link to comment https://forums.phpfreaks.com/topic/90425-count-with-select/#findComment-463676 Share on other sites More sharing options...
aschk Posted February 11, 2008 Share Posted February 11, 2008 As steelerman99 suggested... Try this: SELECT name, ,COUNT(*) as 'total' FROM tbl GROUP BY name Link to comment https://forums.phpfreaks.com/topic/90425-count-with-select/#findComment-463858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.