0

Is it possible to use a "joker selector" into a SELECT request, in order to be able to get an undefined number of column according to what is contained in their name?

For example, I want to get all the %_FK columns using a request like:

SELECT `%_FK`
FROM `table`
WHERE `FILTER` = 'value';
Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32
anael
  • 17
  • 6

2 Answers2

1

That is not possible. You have either to select all columns with * of define the column name explicitly.

If you want to use dynamic SQL you could do something like

PREPARE stmt FROM 'select id from table';
execute stmt;
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

There's more info about this here:

Selecting all columns that start with XXX using a wildcard?

I would suggest preparing the column names in your used programming language, and then push them into the query string afterwards.

Community
  • 1
  • 1
Kao
  • 2,242
  • 3
  • 22
  • 31
  • I wanted to avoid either preparing names or filtering them afterwards, it could have been quite useful to do it directly in mySQL. Thanks anyway ! – anael Jul 20 '12 at 09:47
  • Unfortunately not possible in MySQL. – Kao Jul 20 '12 at 09:50