tcollie Posted May 31, 2007 Share Posted May 31, 2007 I have the following code for finding exact matches for records in my users table containing the same ip address. SELECT * FROM users WHERE ipaddress IN (SELECT ipaddress FROM users GROUP BY ipaddress HAVING COUNT(*) > 1) This returns a listing of user accounts with the EXACT SAME ip address registered. What I want to also be able to find is records with similar IP addresses. For an example, 127.0.0.1 127.0.0.15 would be returned as similar matches. I currently only want to ensure that the first 3 parts (127.0.0.*) are exact matches and the fourth part of the ip is the wildcard. Can somebody help me out with this or point me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/53795-find-similar-ips-in-database/ Share on other sites More sharing options...
tcollie Posted June 1, 2007 Author Share Posted June 1, 2007 -bump- Any ideas on this? Quote Link to comment https://forums.phpfreaks.com/topic/53795-find-similar-ips-in-database/#findComment-266558 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Share Posted June 2, 2007 I think this would work with LIKE in the sql statement. SELECT * FROM users WHERE ipaddress LIKE 'ipvar%' Before that declare ipvar to what you want the first digits to be. % is the wildcard, and will return anything there. Quote Link to comment https://forums.phpfreaks.com/topic/53795-find-similar-ips-in-database/#findComment-266592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.