如何在mysql中组合两列并将其作为一列?

时间:2016-10-07 04:55:16

标签: php mysql codeigniter

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

select * from table and combine as team_c

,结果应该像一列..

team_c as

barcelona
milam
real
inter

team_c 中的所有行应该不同.. 因为我需要在自动完成下拉菜单中显示两个?

5 个答案:

答案 0 :(得分:1)

尝试此查询:

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

答案 1 :(得分:0)

为什么要将这些数据存储到额外的表中。你可以使用像

这样的选择查询
select team_a as team_c from table Union select team_b from table

答案 2 :(得分:0)

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

您可以使用CONCAT_WS组合它们。 希望它会有用!

答案 3 :(得分:0)

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

你可以试试输出会喜欢

巴塞罗那皇家马德里

米兰国际米兰

答案 4 :(得分:-1)

我认为this应该可以解决您的问题:

SELECT team_A AS team_C FROM table UNION SELECT team_B FROM table