Sam
Sam

Reputation: 313

How can I count unique records from a column in my MySQL database?

I'm coding an analytics script for my website that tracks traffic sources. When a user visits a page the following info gets recorded in my database: page, referrer, date, ip. I want to list the different referrers in a table along with the number of times that unique referrer shows up in the column.

Upvotes: 2

Views: 339

Answers (2)

ajmartin
ajmartin

Reputation: 2409

SELECT referrer, COUNT(referrer) FROM table_name GROUP BY referrer;

Upvotes: 0

sasfrog
sasfrog

Reputation: 2460

select referrer, count(*) as NumberOfHits from yourTable group by referrer

Upvotes: 7

Related Questions