Selecting all columns that start with XXX using a wildcard?

前端 未结 5 2260
一生所求
一生所求 2020-11-29 10:58

I have several columns in my databases with similar names. How do I select those based on the word they start with? Here\'s an example table layout:

5条回答
  •  醉梦人生
    2020-11-29 11:44

    You'd have to build the SQL dynamically. As a starting point, this would get you the column names you're seeking.

    SELECT COLUMN_NAME
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE table_name = 'Foods'
            AND table_schema = 'YourDB'
            AND column_name LIKE 'Vegetable%'
    

提交回复
热议问题