sai vamshigupta
sai vamshigupta

Reputation: 41

how to combine two columns in mysql and make it as one column?

+-----+---------------+---------------+
| id  |    team_A     |    team_B     |
+-----+---------------+---------------+
|  1  |   Barcelona   |  Real Madrid  |
+-----+---------------+---------------+
|  2  |     Milan     |     Inter     |
+-----+---------------+---------------+

select * from table and combine as team_c

and result should be like one column..

team_c as

barcelona
milam
real
inter

all rows should in team_c should be different.. because i need two show in an autocomplete dropdown?

Upvotes: 2

Views: 3644

Answers (5)

Saroj Shrestha
Saroj Shrestha

Reputation: 1

I think this should solve your question:

SELECT team_A AS team_C FROM table UNION SELECT team_B FROM table

Upvotes: -1

Rakesh Sojitra
Rakesh Sojitra

Reputation: 3658

Why are you store that data into extra table. You can do using select query like

select team_a as team_c from table Union select team_b from table

Upvotes: 0

Pranav MS
Pranav MS

Reputation: 2296

SELECT CONCAT( team_A," ",team_B) AS team_c FROM table;

You can try this output will like


Barcelona Real Madrid

Milan Inter

Upvotes: -1

Razib Al Mamun
Razib Al Mamun

Reputation: 2713

Try this query :

select a.team_a as team_c from table a Union select b.team_b from table b

Upvotes: 4

Mohamed Nizar
Mohamed Nizar

Reputation: 777

SELECT team_A, team_B , CONCAT_WS('', team_A, team_B) AS team_C, from table;

You can combine them using CONCAT_WS. Hope it will usefull!

Upvotes: -1

Related Questions