【发布时间】:2011-06-03 07:56:25
【问题描述】:
SELECT icon_* FROM
imagesWHERE 1
我有三个字段,icon_small、icon_big 和 icon_large。如何在不手动指定的情况下获得所有三个?
【问题讨论】:
SELECT icon_* FROM
imagesWHERE 1
我有三个字段,icon_small、icon_big 和 icon_large。如何在不手动指定的情况下获得所有三个?
【问题讨论】:
据我所知,你不能。您必须手动指定它们。
(查看副本)
【讨论】:
您必须在 SELECT 中指定它们,但您可以通过以下方式选择列列表(然后只能在 dynamic SQL 中使用):
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;
【讨论】: