I am having a problem with my SQL query?

When I run: SELECT DISTINCT groupLetter FROM well_tbl
I get:
|groupLetter |
|group A |
|group B |

When I run: SELECT COUNT() FROM well_tbl
I get:
|78 |

I will like to count all records pertaining to their respective groupLetters, so I ran:
SELECT COUNT(*) FROM well_tbl WHERE groupLetter = “(SELECT DISTINCT groupLetter FROM well_tbl)”

and I got:
|78 |

What am I missing?

I am using PHP/MySQL

GROUP BY is your friend.

SELECT groupLetter
     , COUNT(*) AS letterCount
  FROM well_tbl
 GROUP BY groupLetter

@DaveMaxwell, thanks so much, it worked. Please any MySQL references in pdf you can recommend to me, given that I am mostly offline.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.