1

I have a database with columns with the same name and a number after it, like: med1, med2, med3, med4..... etc.

Is it posible to do something like this:

Select medewerker.med*
FROM table

Instead of this?:

Select medewerker.med1, 
       medewerker.med2,  
       medewerker.med3, 
       medewerker.med4
FROM table
rdhoon
  • 23
  • 4
  • Did it work? No. I'm guessing no then! ;-) – Strawberry Nov 25 '14 at 12:56
  • 2
    possible duplicate of [Wildcards in column name for MySQL](http://stackoverflow.com/questions/11466764/wildcards-in-column-name-for-mysql) – Phillip Nov 25 '14 at 12:56
  • 1
    Having multiple columns with the same name and type and with enumerated names is usually a sign of a poor database design. Typically, you want to replace the columns with a junction table. – Gordon Linoff Nov 25 '14 at 12:57
  • 2
    However, this points to a more serious problem with your data model - i.e. a lack of normalization. – Strawberry Nov 25 '14 at 12:57
  • In short, no you can't. See [this](http://stackoverflow.com/questions/11466764/wildcards-in-column-name-for-mysql) question. – Siebe Nov 25 '14 at 12:57
  • The question is, is there any way so it DOES work? – rdhoon Nov 25 '14 at 12:58

2 Answers2

0

Nope. you can use LIKE in a where clause but definitely not when specifying the columns to select

Sheldon Neilson
  • 803
  • 4
  • 8
0

Use this instead if the only fields are the ones specified above.

SELECT *
FROM table

if not you cannot use a LIKE statement on column SELECT's.

if you are refering to values inside the medewerker column then use

SELECT *
FROM table
WHERE medewerker LIKE 'med%'
Matt
  • 14,906
  • 27
  • 99
  • 149