Fresh_ales Posted March 22, 2007 Share Posted March 22, 2007 First hi to all I want to make a query in MySQL and have some problems with it... I have made it like this $query = "SELECT * FROM $db_stats WHERE user_ip NOT IN ( SELECT user_ip FROM $db_stats GROUP BY user_ip ) "; so.... what it want? i have user_ip-s in my db and i want to select all records that are more then 1 in database... that means i there are 2 same ips i want to select one of them.... on the end when i see the query works well i want to delete this records... help? Quote Link to comment Share on other sites More sharing options...
mem0ri Posted March 22, 2007 Share Posted March 22, 2007 Why don't you do the initial sorting at the INSERT end instead of running a cleanup after the fact? Just make the USER_IP a 'key' and run an INSERT......ON DUPLICATE KEY UPDATE... Of course...if you already have the database, then that's not an option for the current clean-up need. I'm actually not sure how to search the table to only get duplicated rows. Quote Link to comment Share on other sites More sharing options...
Fresh_ales Posted March 22, 2007 Author Share Posted March 22, 2007 i know that.... but this is the case... i have database and need to cleen it up... Quote Link to comment Share on other sites More sharing options...
Barand Posted March 22, 2007 Share Posted March 22, 2007 SELECT user_ip, COUNT(*) as tot FROM $db_stats GROUP BY user_ip HAVING tot > 1 Quote Link to comment 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.