0

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?

Community
  • 1
  • 1
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242

3 Answers3

3

As far as I know, you can't. You will have to manually specify them.

(See the duplicate)

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1

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_%'
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
davek
  • 22,499
  • 9
  • 75
  • 95
0
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;
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98