Packy
Packy

Reputation: 3593

Remove commas from database column

Basically in a table I want to remove all commas in metadata_value column entries someone put in where meta_key column is equal to 15, 16, or 17

So:

SELECT REPLACE(metadata_value, ',', '')
FROM project_content_to_metadata
WHERE metadata_key = '15'
AND metadata_key = '16'
AND metadata_key = '17'

But it did not work

Upvotes: 1

Views: 1048

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1271131

If you actually want to remove the commas in the table, then use update:

update project_content_to_metadata
    set metadata_value =  REPLACE(metadata_value, ',', '')
    where metadata_key in (15, 16, 17);

Otherwise Kamil's answer is correct.

Upvotes: 1

Kamil Gosciminski
Kamil Gosciminski

Reputation: 17177

Your REPLACE is correct, but use OR instead of AND. One row can't have 3 different values. You could use IN to specify multiple OR conditions on one column:

SELECT REPLACE(metadata_value, ',', '')
FROM project_content_to_metadata
WHERE metadata_key IN ('15','16','17')

Also, if your metadata_key is of type Integer do not use quotes around values, so this could be:

metadata_key IN (15,16,17)

Upvotes: 3

Related Questions