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

  • SEARCH
  • Home
  • 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 8014659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:00:33+00:00 2026-06-04T20:00:33+00:00

I have a table of ‘games’ with a different entry for each game like

  • 0

I have a table of ‘games’ with a different entry for each game like so:

gameID   internalName
1        game1
2        game 1
3        game 2
4        game2
5        game3

etc.

So, the problem is now that I want to combine cases where the game’s titles (with whitespace stripped) are identical. In other the row with gameID of 2 would be merged with 1, and removed.

In addition, I want to update any entries in other tables that are using the gameID as a foreign key, to point to the new key.

I know I can do something like so, to get a list of which titles have duplicates:

SELECT gameID, count(REPLACE(internalName, ' ', '')), internalName  FROM games GROUP BY REPLACE(internalName, ' ', '') HAVING count(REPLACE(internalName, ' ', ''))  > 1

However, that doesn’t really help me to achieve what I need to do.

Any help?

  • 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-04T20:00:34+00:00Added an answer on June 4, 2026 at 8:00 pm

    something like that could help you to start

    select g1.gameID as toKeep, g2.gameID toEliminate
    from games g1
    inner join games g2 on replace(g1.internalName, ' ', '') = replace(g2.internalName, ' ', '')
    where g1.gameID < g2.gameID
    

    but if you have 3 items to merge, this won’t work that well…

    see http://sqlfiddle.com/#!2/fb294/6

    but within a stored procedure or in php (or other language), you should be able to get what you want with that.

    BETTER

    with this one, even 3, or 4, or 5 identical result will work

    select g1.gameID as toKeep, g2.gameID toEliminate
    from games g1
    inner join games g2 on replace(g1.internalName, ' ', '') = replace(g2.internalName, ' ', '')
    where g1.gameID < g2.gameID
    and g1.gameID not in (SELECT g4.gameID
                          from games g4
                          inner join games g3 on replace(g3.internalName, ' ', '') = replace(g4.internalName, ' ', '')
                          where g3.gameID < g4.gameID)
    

    http://sqlfiddle.com/#!2/8fb21/1

    EDIT : an example of (untested) stored procedure

    CREATE PROCEDURE CLEANGAMENAMES()
    BEGIN
      DECLARE toKeep, toEliminate INT;
      DECLARE cur1 CURSOR FOR 
        SELECT g1.gameID AS toKeep, g2.gameID AS toEliminate
        FROM games g1
        INNER JOIN games g2 ON REPLACE(g1.internalName, ' ', '') = REPLACE(g2.internalName, ' ', '')
        WHERE g1.gameID < g2.gameID
        AND g1.gameID NOT IN (SELECT g4.gameID
                              FROM games g4
                              INNER JOIN games g3 ON REPLACE(g3.internalName, ' ', '') = REPLACE(g4.internalName, ' ', '')
                              WHERE g3.gameID < g4.gameID)
    
      OPEN cur1;
    
      read_loop: LOOP
        FETCH cur1 INTO toKeep, toEliminate;
        UPDATE <anyTable> set gameId = toKeep where gameId = toEliminate;
        -- as many tables as you need
        DELETE FROM games where gameID = toEliminate;
        UPDATE games set internalName = REPLACE(internalName, ' ', '');
    
      END LOOP;
    
      CLOSE cur1;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table called Direccion other called Cliente each one defined like this public
I have table with countries, resorts and photos for resorts. Each photo may be
I have table field defined as like this approved_at DATETIME YEAR TO SECOND NOT
I have table in an MS Access database that looks like this: ID Symbol
I have table X, and each record in X has many records in Y.
I have table like below ID User Date Location 1 Tom 6-Mar-2012 US 2
I have table like below : <table> <thead> <th>Product Type</th> <th>Quantity</th> <th>Unit</th> <th>Total</th> </thead>
I have table (call it my_table ) that can be simplified like this: NAME,
I have table like this: +------+-------+ | user | data | +------+-------+ | 1
I have table of user actions, each having a user associated, a type, and

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.