1

Is it possible to use something like this to select all fields starting with certain word like:

Mytable

id     title_en    name_en      title_fr     name_fr
=======================================================
1      Title1      Name1        Title2       Name2


SELECT title_*, name_* FROM Mytable;
Alko
  • 1,421
  • 5
  • 25
  • 51
  • no, it is not possible. I mean there is no simple way to do that. but you can create some stored procedure wich will analize `INFORMATION_SCHEMA` http://dev.mysql.com/doc/refman/5.7/en/columns-table.html tables and find all columns you need. But I don't think that is best approach in your case – Alex Jun 08 '16 at 18:10
  • 1
    You actually do not want to do that. You want to name precisely what columns you want to receive back with what content inside (can also be computed content). Everything else causes issues when your data model changes over time... – arkascha Jun 08 '16 at 18:15

2 Answers2

1

You'll need to grab a list of all the fields with something like DESCRIBE mytable, filter out the ones you want, then specify those literally.

There's no SQL standard way of doing this, and MySQL has no specific extension to allow for it.

tadman
  • 208,517
  • 23
  • 234
  • 262
0

You should to do additional query to get fields names.

SHOW COLUMNS FROM table

or

DESCRIBE table

And then to make SELECT by those fields.

Similar, but with UPDATE: Mysql update all columns starting with same Name

Community
  • 1
  • 1
jekaby
  • 403
  • 3
  • 13