Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:07:19+00:00 2026-06-13T12:07:19+00:00

I have duplicate IP Address records in my database like this : id |

  • 0

I have duplicate IP Address records in my database like this :

id | ipaddress
1    192.168.xxx.xxx
2    192.168.xxx.xxx
3    111.118.xxx.xxx
4    111.118.xxx.xxx

I want unique ip addresses in my field. How should I delete all duplicate entry?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:07:20+00:00Added an answer on June 13, 2026 at 12:07 pm

    Deleting duplicates in MySQL is a bit tricky because of the stupid restriction that the table cannot be referenced in a sub-select. Therefor the sub-select needs to be re-written into a join:

    DELETE d
    FROM mytable d
    LEFT JOIN (
       SELECT min(id) as min_id
       FROM   mytable
       GROUP BY trim(ipaddress)
    ) tokeep ON tokeep.min_id = d.id
    WHERE keep.min_id IS NULL;
    

    SQLFiddle demo: http://sqlfiddle.com/#!2/9cfb9c/1

    Edit

    There is actually a way to get around the stupid sub-select restriction. If the table is wrapped into a derived table inside the sub-select, the MySQL parser doesn’t notice this and happily deletes with a sub-select:

    delete mt 
    from mytable mt
    where exists (
        select * 
        from (
          select id, ipaddress
          from mytable
        ) ex
        where TRIM(ex.ipaddress) = TRIM(mt.ipaddress)
       and ex.id < mt.id
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
I have a SQL Server 2008 R2 database table with 12k address records where
I have a table that has duplicate email address, I need to insert just
I have duplicate entries in my log file for NServiceBus and I'm concerned this
I have a SQL Server 2008 database with 2 tables. These tables are Address
Let's say I have 2 tables in my database. users and combineusers I want
I have an InnoDB table that lists customer orders - this table records the
I have many examples of this through my database. Below is a simple example
I have 'records' (basically CSV strings) of two names and and one address. I
Possible Duplicate: What characters are allowed in email address? I have an email address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.