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 9047829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:59:54+00:00 2026-06-16T11:59:54+00:00

I have a table contacts that contains columns index_id , name , address ,

  • 0

I have a table contacts that contains columns index_id,name,address,phone1,phone2,phone3.

Due to poor management over the years, there are 212,019 rows out of 484,097 where phone1 is not unique. However, each record is a unique record.

I need phone1 to be unique, but I don’t want to lose 212k records doing it.

phone3 is a new column that is null for each record. My thought is I could simply move* VALUES(phone1) into phone3

I tried this query not understanding that ON DUPLICATE UPDATE would simply update the previously existing record.

insert into tmp select * from contacts
on duplicate key update phone3 = values(phone1);

I tried just moving* all the duplicates over to phone3 with

update contacts 
set phone3 = phone1
where count(phone3) > 1;

But that’s an invalid use of group function.

I’m thinking this is going to require a subquery, that’s where I start to get confused. Are there any suggestions?

*move is to mean that the data would no longer be in phone1 but rather would be in phone3. as in phone1 = NULL and phone3 = data

  • 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-16T11:59:55+00:00Added an answer on June 16, 2026 at 11:59 am

    This will move all duplicated phone1 to column phone3. Phone1 will be set to null for every record where there’s a duplicate:

    UPDATE
      contacts c1 inner join (select phone1
                              from contacts
                              group by phone1
                              having count(*)>1) c2
      on c1.phone1=c2.phone1
    SET
      c1.phone1=null, c1.phone3=c1.phone1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
I have a table that contains the columns: employer_id contact_id primary First two are
I have a table, contacts, that has a dozen columns or so. I want
I have a table contacts that has a field arrayOfMembers (JSON format) and a
I have a database named contacts.db with a table named TABLE_NAME that has one
I have a contacts table: ID NAME --- ---- 1 KK 2 JKI 3
I have a table in a database that contains a variety of paths to
I have got 2 tables: Contacts and Users . Contacts table contains user_id which
We have a SQL Server table containing Company Name, Address, and Contact name (among
I have a .db file that contains the contacts list from an android phone.

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.