Wildcards in column name for MySQL

后端 未结 4 984
情话喂你
情话喂你 2020-12-09 19:58

I am trying to select multiple columns, but not all of the columns, from the database. All of the columns I want to select are going to start with \"word\".

So in ps

4条回答
  •  無奈伤痛
    2020-12-09 20:51

    This could be helpful: MySQL wildcard in select

    In conclusion it is not possible in MySQL directly.

    What you could do as a dirty workaround is get all the column names from the table with an initial query (http://dev.mysql.com/doc/refman/5.0/en/show-columns.html) and then compare in python if the name matches your pattern. Afterwards you could do the MySQL select statement with the found column names like this:

    SELECT word1, word2, word3 from searchterms where onstate = 1;
    

提交回复
热议问题