Home > OS >  SQL QUERY Append Two Columns
SQL QUERY Append Two Columns

Time:07-14

I am still learning on SQL Statements How do I append two columns?

E.g

Table 1

    | ID | Name      | Position  | 
    ------------------------------
    | 1  | Mike      | Developer
    | 2  | Mark      | QA        |

Expected Result

Table 2
    
    | ID | User Role/Name |
    -----------------------
    | 1  | Mike           |
    | 1  | Developer      |
    | 2  | Mark           |
    | 2  | QA             |
    -----------------------

CodePudding user response:

Use union all:

select ID, Name as "User Role/Name" from table1
union all
select ID, position from table1
order by ID

DEMO

CodePudding user response:

Do you means that it will output like it?


select ID, concat(Position,'/',Name) from Table2

| ID | User Role/Name |
-----------------------
| 1  | Developer/Mike |
| 2  | QA/Mark        |
  •  Tags:  
  • sql
  • Related