Showing posts with label inelegant. Show all posts
Showing posts with label inelegant. Show all posts

Monday, April 20, 2009

[SQL] Counting Rows with the Same Value of a Given Field

Here's a piss-easy script to count the number of rows in a table where a given field has the same value:

SELECT myField, COUNT(*) AS 'inelegantCount'
FROM myTable
GROUP BY myField

It's the classic GROUP BY statement example - which I can't manage to remember, thus the blog post.