0

Hi How can I add REPLACE to the following query?

SELECT SUBSTRING(title,1,1) AS titlealpha,
COUNT(title)
FROM serien
WHERE not_seen =''
GROUP BY titlealpha;

From an alphabetical list, with titlealpha I try to replace extraordinary letters, like öäüéàè, into normal abc... letters.

REPLACE(titlealpha, 'ä', 'a')
REPLACE(titlealpha, 'ö', 'o')

Is there also a short, clean way?

2 Answers 2

1

a easy way is to replace the this in all rows. MySQL only write the Record if it change

like

UPDATE serien set title = replace(title, 'ä' , 'a');

or you can put multi replaces in one Statement

UPDATE serien set title = REPLACE( REPLACE(title, 'ä' , 'a'), 'Ä', 'A');

ans so on

1
  • With your suggestion the database entries get changed. I don't wanna change them, just read out for my special case. Thanks anyway. But is it possible to update the AS titlealpha within the query? Or is this not working, because what I'm afraid of, the query needs a hard table, not an alias?
    – doschni
    Aug 23, 2015 at 12:36
0

try

SELECT REPLACE(REPLACE(SUBSTRING(title,1,1), 'ä', 'a'), 'ö', 'o') 
AS titlealpha,
COUNT(title)
FROM serien
WHERE not_seen =''
GROUP BY titlealpha;
1
  • Thanks a lot, this works great! First I thought, it don't. Then I realized the upper and lower case is also important.
    – doschni
    Aug 23, 2015 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.