Can i get all possibilities of enum column type by one query?
For example, i have column colors with possibilities 'red', 'green', 'blue'.
I want to get something like this:
colors
------
red
green
blue
or
colors
------
red, green, blue
Can i get all possibilities of enum column type by one query?
For example, i have column colors with possibilities 'red', 'green', 'blue'.
I want to get something like this:
colors
------
red
green
blue
or
colors
------
red, green, blue
If you would like to get the actual values present in this column, try this:
SELECT DISTINCT color FROM colorenum
If you are going to get all values that are allowed for this column, try:
SHOW COLUMNS FROM colorenum WHERE Field = 'color'
see example here: http://www.sqlfiddle.com/#!2/d27350/1
or
SELECT COLUMN_TYPE
FROM information_schema.COLUMNS
WHERE TABLE_NAME='colorenum' AND COLUMN_NAME = 'COLOR';
This one will return enum('red','green','blue','white','yellow','black')
for example.
or
SELECT REPLACE(
(REPLACE(
(REPLACE(
(REPLACE(
(SELECT COLUMN_TYPE
FROM information_schema.COLUMNS
WHERE TABLE_NAME='colorenum' AND COLUMN_NAME = 'COLOR')
, 'enum(', '')),
')', '')),
'\'', '')),
',', ', ');
This one will return red, green, blue, white, yellow, black
for example.