Snappysites Snappysites - 1 year ago 43
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
and only visited a single page of the website.

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

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

Answer Source

Try this query:

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