问题
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