MySQL - Selecting the same column resulting in 2 different output

Firdaus Indradhirmaya :

I have table that looks like this:

item_id | item_name
--------+-------------
123     | Blue_Ocean
234     | Green_Grass

I would like to query the columns from that table, so that the result would be like so,

item_id | item_name   | item_name_without_underscore
--------+-------------+------------------------------
123     | Blue_Ocean  | Blue Ocean
234     | Green_Grass | Green Grass

Is this possible with just a query? Or do I have to parse the result that I want in the backend side of my app?

Gordon Linoff :

You can use replace():

select item_id, item_name,
       replace(item_name, '_', ' ') as item_name_without_underscore
from t;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=386204&siteId=1