Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > MySQL query question

MySQL query question
Thread Tools
joeakablue
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Sep 5, 2002, 07:33 AM
 
Searching for duplicate IP addresses in a database, what's the best way to handle this? I've pulled most of my hair out trying to dig through the mysql and php resources online in an effort to return this information:

selecting non unique IP addresses from a mysql table. Sort of reverse the results you'd get from

SELECT DISTINCT ip_address FROM table_name

This has got to be an easily done thing. Any help anyone can offer? I'm new to this kind of thing, but have learned a lot int he last year of OS X and web development.

thanks in advance!
joe
     
pumpkinapo
Junior Member
Join Date: Aug 2000
Location: Califon, NJ
Status: Offline
Reply With Quote
Sep 5, 2002, 08:32 AM
 
I've done something similar with MSSQL 2000, but the SQL code should be similar. Try this, it'll list all the ipaddress but the duplicates will be at the top of the list.

SELECT ip_address, count(ip_address) FROM table_name GROUP BY ip_address ORDER BY count(ip_address) desc

You should get a listing similar to this:
10.1.1.1 2
10.1.1.2 2
10.1.1.3 1

First column is the ip address, second column is the number of times it appears.

Hope this helps.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:50 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,