从单个表PHP&中的多个列中获取数据SQL

时间:2015-02-12 10:16:13

标签: mysql

我有一个表和5列,其中一些值类似于彼此的颜色。现在我想在html选择字段中获取这些列的所有数据。![在此处输入图像描述] [1]

SELECT CONCAT (chemical_entity_0, chemical_entity_1, chemical_entity_2, chemical_entity_3, chemical_entity_4, chemical_entity_5, chemical_entity_6, chemical_entity_7, chemical_entity_8, chemical_entity_9) AS chemical_entity 
FROM msds

1 个答案:

答案 0 :(得分:0)

如果您想要每列一行,请使用UNION: -

SELECT chemical_entity_1 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_2 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_3 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_4 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_5 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_6 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_7 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_8 AS chemical_entity 
FROM msds
UNION ALL
SELECT chemical_entity_9 AS chemical_entity 
FROM msds