I have a problem i’m not sure how to solve.
To simplify my problem there is a table with links:
fk linkid link
1 1 www.stackoverflow.com
1 2 www.google.com
1 3 www.cnn.com
2 4 www.other.com
Then i have another table with a string-column where a user can insert these keys and then it should replace them. You enter a key like L{a number}, like L1. “L1” should then be replaced with linkid 1..
id string_column
1 "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}"
2 "Go here: {L4}"
So when i join them for id 1 i get this:
id linkid link string_column
1 1 www.stackoverflow.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}"
1 2 www.google.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}"
1 3 www.cnn.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}"
What i would like to get is:
id string_column
1 "Hi my first link is www.stackoverflow.com. More text www.stackoverflow.com www.stackoverflow.com www.cnn.com www.google.com"
Is it possible in mysql to write such an sql?
As you can see above i need to make a replace on 1 column but get the values from multiple rows and then only return 1 per id.
Since the system is already the way it is i can’t change the setup but just have to find a way to get this right.
the only way I see to do this would be a script doing the work, where you take out all the sentences, cut the number from the L, search the corresponding link and replace all {L1} by that link. then you update the db with the new string.