Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


Question:how to Merge mysql colums to rows


I have a table with the following structure:

+-----+------------+------------+------------+------------+
| ID  |  FEATURE1  |  FEATURE2  |  FEATURE3  |  FEATURE4  |
+-----+------------+------------+------------+------------+
|  1  |  red       |  blue      |  black     |  grey      |
|  2  |  yellow    |            |            |            |
|  3  |  orange    |  red       |  green     |  golden    |
|  4  |  orange    |  grey      |  blue      |            |

What I would like to do is query the table and return all possible features for use in an autocomplete call. I need the query to only return unique values.

SELECT (FEATURE1, FEATURE2, FEATURE3, FEATURE4, FEATURE5) FEATURE
FROM products
WHERE `FEATURE` LIKE 'gr%\'

My desired output would be:

+----------+
| FEATURE  |
+----------+
|  green   |
|  grey    |

mysql sql query merge

asked Sep 13, 2013 in MYSQL by rajesh
edited Sep 12, 2013
0 votes
16 views



Related Hot Questions



Government Jobs Opening


...