Possible Duplicate:
MySQL wildcard in select …
SELECT icon_* FROM
images
WHERE 1
I have three fields, icon_small
, icon_big
, and icon_large
. How do I get all three without manually specifying them?
Possible Duplicate:
MySQL wildcard in select …
SELECT icon_* FROM
images
WHERE 1
I have three fields, icon_small
, icon_big
, and icon_large
. How do I get all three without manually specifying them?
As far as I know, you can't. You will have to manually specify them.
(See the duplicate)
You have to specify them in your SELECT
, but you can select a list of columns (which can then only be used in dynamic SQL) by doing:
select column_name from information_schema.columns
where table_schema = database()
and table_name = 'mytesttable'
and column_name like 'icon_%'
set @qry = (select concat('select ',group_concat(column_name), ' from ' ,table_name) from
information_schema.columns
where table_schema = database()
and table_name = 'your_table_name'
and column_name like 'icon_%');
prepare stmt from @qry;
execute stmt;
deallocate prepare stmt;