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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:24:08+00:00 2026-05-25T23:24:08+00:00

trying to rename duplicates in MySQL database so far using that code but this

  • 0

trying to rename duplicates in MySQL database so far using that code but this only adding 1 at the end of name. So if I have

    UPDATE phpfox_photo n 
  JOIN (SELECT title_url, MIN(photo_id) min_id FROM phpfox_photo GROUP BY title_url HAVING COUNT(*) > 1) d
    ON n.title_url = d.title_url AND n.photo_id <> d.min_id
SET n.title_url = CONCAT(n.title_url, '1'); 


Anna
Anna
Anna

Result is

Anna
Anna1
Anna11

When I got 200 Annas result is Anna1111111111111111111111111111111111111111111….etc

how do I do it to rename in the following inc

Anna
Anna1
Anna2
  • 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-05-25T23:24:09+00:00Added an answer on May 25, 2026 at 11:24 pm

    if i didn’t miss something you can make a stored procedure that iterates throw your rows using cursors to do that as following:

    DECLARE counter INT DEFAULT 0;
    DECLARE num_rows INT DEFAULT 0;
    DECLARE offset INT;
    DECLARE title_urlvalue VARCHAR(50);
    DECLARE no_more_rows BOOLEAN;
    DECLARE ucur CURSOR FOR
      SELECT
        UPDATE phpfox_photo n 
        JOIN (SELECT title_url, MIN(photo_id) min_id 
        FROM phpfox_photo GROUP BY title_url HAVING COUNT(*) > 1) d
        ON n.title_url = d.title_url AND n.photo_id <> d.min_id;
    SET offset = 1;
    SET no_more_rows = TRUE;
    select FOUND_ROWS() into num_rows;
    OPEN ucur;
    uloop: LOOP
      FETCH  ucur
      if counter >= num_rows then
        no_more_rows = False;
      endif
      INTO   title_urlvalue;
      IF no_more_rows THEN
        CLOSE ucur;
        LEAVE uloop;
       END IF;
       update title_urlvalue = Concat(title_urlvalue,offset);
      SET offset = offset + 1;
      SET counter = counter + 1;
    END LOOP uloop;
    close ucur;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rename my table using this SQL. I'm using MySQL 5.1.41 on
I'm trying to rename a column using sp_rename but it's referenced in a computed
We're trying to rename a column in MySQL (5.1.31, InnoDB) that is a foreign
I am trying to rename a directory in c# to a name that is
I'm trying to rename a database to a name with a hyphen (-). ALTER
I am trying to rename all the files present in a Windows directory using
I'm trying to rename the columns. The syntax should be the column name between
I'm trying to rename some files, but getting a baffling error*. When I run
I am trying to rename files with a dash in the name to ensure
I am trying to understand why this design decision was made with the rename()

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.