Snappysites Snappysites - 3 months ago 8
PHP Question

MySQLi count where one column is the same and another column is different

I have a table which stores visitor information to certain websites and it is laid out like this:

ip_address | website_ref | page_visited

123.123.12 abc index.php
123.123.12 abc anotherpage.php
123.123.12 efg index.php
987.987.98 abc index.php


I am trying to get the script to count any IP addresses which have the same
Website_Ref
and only visited a single page of the website.

In the example above, the system for
abc
should count
987.987.98
but not
123.123.12
because
123.123.12
visited more than a single page.

How would I code my MySQLi query to count only these results?

Answer

Try this query:

select * from table_name group by ip_address, website_ref having count(*) = 1