我想从组合表中所有列的一列中提取数据。它适用于 SELECT
方法。
ID FirstName LastName
1 John Doe
2 Bugs Bunny
3 Kim Johnson
我该如何将结果显示为:
ALIAS
1
2
3
John
Bugs
Kim
Doe
Bunny
Johnson
谢谢你帮助我
最佳答案
您需要 UNION(或 UNION ALL)查询:
select ID as ALIAS from tablename
union all
select FirstName as ALIAS from tablename
union all
select LastName as ALIAS from tablename
UNION 查询将返回不同的值,UNION ALL 则返回所有值。如果你想保留顺序,则需要额外的一列:
select ALIAS from
(
select id, ID as ALIAS, 1 as col from tablename
union all
select id, FirstName, 2 as col from tablename
union all
select id, LastName, 3 as col from tablename
) s
order by col, id
关于MySQL-如何从组合表中所有列的一列中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34634722/