I have a table with three columns and one stores the users ip address. I want to query, but want to restrict it so that users with their ip in the ip_address column are only counted once. Here is my current query
SELECT COUNT(*) FROM articles where article_id = '1'
GROUP BYclause for MySQL. Also, ask programming questions on StackOverflow.GROUP BYoverDISTINCTasGROUP BYallows you to specify which columns you want unique values. AlthoughDISTINCTappears to be a function call on a column, it's not - it tries to make each row unique rather than just what you specify.DistinctandGroup Byserve completely different purposes. OP just wants to count unique ip addresses onceDISTINCTand 1 usingGROUP BY. I was merely giving the OP a direction on which (I think) is the way to go. Unless I misunderstood his question =)DISTINCTandGROUP BYfor this particular problem. If the OP wanted a list of unique IPs, then the answers withDISTINCTand those withGROUP BYwould most probably look very similar. You might say, it's because both of them modify SELECT. But of the two only DISTINCT can also be used to modify COUNT, and count is what the OP wants. With GROUP BY you would just have to resort to subselecting, an unnecessary option here, I think.