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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:15:23+00:00 2026-06-18T23:15:23+00:00

this is the first time I’m posting here! Hope to get a good reply.

  • 0

this is the first time I’m posting here! Hope to get a good reply.

I have two table, and based on the path I need to locate and replace with ” the name of table2 in the name of table1.

table1
+---------------+----------+
| name          | path     |
+---------------+----------+
| John Smith    | 12345    |
+---------------+----------+
| John Smith    | 54321    |
+---------------+----------+
| JohnSmith     | 12345    |
+---------------+----------+

table2
+---------------+----------+
| name          | path     |
+---------------+----------+
| John          | 12345    |
+---------------+----------+
| Smith         | 54321    |
+---------------+----------+

the final result would be like
+---------------+----------+
| name          | path     |
+---------------+----------+
| Smith         | 12345    |
+---------------+----------+
| John          | 54321    |
+---------------+----------+
| JohnSmith     | 12345    |
+---------------+----------+

as you can see I need to replace only the exact match. So in JohnSmith I don’t remove John.

The question is also, do I do it only with a mysql query? Or some php is also needed for something like that?

Thank you in advance.


both queries are close, but don’t give exactly what I need as an output.

e.g. the first one produce

NAME        PATH
Smith       12345
John        54321
Smith       12345

here the last row, should not be changes. As we don’t have any exact match. and the row should stay the same “JohnSmith”

in the second one, the output is

NAME        PATH
Smith       12345
John Smith  54321
JohnSmith   12345

here the second line seems wrong, as it should remove “Smith”

any idea ?

  • 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-18T23:15:25+00:00Added an answer on June 18, 2026 at 11:15 pm

    This is close, but I admittedly don’t understand your last condition — shouldn’t it be Smith/12345? This uses REPLACE:

    SELECT REPLACE(t1.Name, t2.Name, '') Name, t1.Path
    FROM Table1 t1
      LEFT JOIN Table2 t2 ON t1.path = t2.path
    

    And here is the SQL Fiddle.

    –EDIT–

    Here is an attempt using a CASE statement. It checks for in the middle, in the beginning, or at the end:

    SELECT 
      CASE 
        WHEN t1.Name Like CONCAT('% ',IFNULL(t2.Name,''),' %')
        THEN REPLACE(t1.Name, CONCAT(' ',IFNULL(t2.Name,''),' '), ' ') 
    
        WHEN t1.Name Like CONCAT(IFNULL(t2.Name,''),' %')
        THEN REPLACE(t1.Name, CONCAT(IFNULL(t2.Name,''),' '), '') 
    
        WHEN t1.Name Like CONCAT('% ',IFNULL(t2.Name,''))
        THEN REPLACE(t1.Name, CONCAT(' ',IFNULL(t2.Name,''),' '), '') 
    
        ELSE
           t1.Name
    
    END Name, t1.Path
    FROM Table1 t1
      LEFT JOIN Table2 t2 ON t1.path = t2.path
    

    And more Fiddle.

    Produces the following results:

    NAME        PATH
    Smith       12345
    John Smith  54321
    JohnSmith   12345
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two update panels at my ajax page. This is first time I'm
So here I have this first time app I'm working on. When I run
this is my first time asking a question here. I tried to be well
This is my first time here and I am a beginner so kindly bear
I have two classes which second inherit by first. then I have this: First[]
this is first time i'm develope paypal form , i have problem with shipping
This is my first time working with a WPF datagrid. From what I understand
This is my first time that I use WCF and Android. So, sorry for
This is my first time using XML documents. What I'm trying to do is
This is the first time, I am involved in writing a complete client for

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.