SELECT * FROM table WHERE (all_columns_begins_with: name%) = Bob

徘徊边缘 提交于 2020-11-29 10:33:46

问题


I have a SQLite table with columns like these: id, name_1, name_2, name_nick, phone, email

and I am looking for a way to search in all columns which begins with name_.

Like LIKE but for the column names.

I find a lot for MySQL etc, but nothing for SQLite.

These queries do not work as I want:

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'Customers'


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

I get this:

ERROR: no such table: information_schema.columns

I have seen this question, which is how to obtain column names using SQL. However I think I would need a scripting language to run the query to get column names, filter them in some fashion, and then construct a new query using the filtered set of names. Instead I would like to try to do this all in SQL, if it is possible.

来源:https://stackoverflow.com/questions/63869593/select-from-table-where-all-columns-begins-with-name-bob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!