1

I have tried looking up this issue but maybe I'm just not searching correctly.

I was wondering if its possible in SQL to concatenate based off the results of another column in the same row. Let me give an example

+-------------+------------+--------+
|    STATE    |    CITY    | Region |
+-------------+------------+--------+
| Georgia     | Atlanta    | East   |
| Los Angeles | California | West   |
+-------------+------------+--------+

Lets say I have this table and I want to make a new column in it by doing some kind of concatenation

The output should look like this

+-----------+------------+-------------+--------+
|   SIDE    |   STATE    |    CITY     | Region |
+-----------+------------+-------------+--------+
| East_Side | Georgia    | Atlanta     | East   |
| West_Side | California | Los Angeles | West   |
+-----------+------------+-------------+--------+

So the Side column should look into region and ask What Region is it? And then say ok so this is "?_Side" Then concatenate the appropriate "Region_Side" = "East_Side"

This is just a simple example, I know in this example I could use a case statement but in my actual application I can't since its a lot of "Regions"

Is this possible or no?

2 Answers 2

2

Does this do what you want?

select Region || '_Side', state, city, region
from t;

|| is the string concatenation operator in Oracle (and in standard SQL as well).

Sign up to request clarification or add additional context in comments.

Comments

1

Just use column and concat the string

select  region ||'_Side', STATE ,  CITY , Region
from my_table  

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.