tags:

views:

42

answers:

1

Basically, ok say my DB table has 2 columns: keyword and date.

I want to select rows but if multiple rows have the same keyword and date I want to group them and get a count of how many there are.

for example instead of getting this:

keyword: diamond, date: 20090601
keyword: diamond, date: 20090601
keyword: diamond, date: 20090602
keyword: diamond, date: 20090602
keyword: diamond, date: 20090602

I would get this:

keyword: diamond, date: 20090601, count: 2
keyword: diamond, date: 20090602, count: 3

Not sure how to do that?

Thanks!

+6  A: 

It's called the GROUP BY clause:

SELECT keyword, date, COUNT(1) AS count
FROM table
GROUP BY keyword, date
Welbog