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
  • 33,798
  • 37
  • 161
  • 232

3 Answers3

3

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

(See the duplicate)

Pekka
  • 431,103
  • 135
  • 960
  • 1,075
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,030
  • 21
  • 100
  • 124
davek
  • 21,791
  • 7
  • 74
  • 94
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
  • 52,276
  • 15
  • 91
  • 96