SELECT count(*) from table WHERE (int(ip/256)*256) = (int($ip_address_to_be_compared_to/256)*256)