選擇icon_ * FROM
images
WHERE 1
我有三個字段,icon_small
,icon_big
和icon_large
。如何在不手動指定它們的情況下獲得全部三項?
選擇icon_ * FROM
images
WHERE 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;