Skip to content
Advertisement

SQLite Select data where the column name contains a string and create a table with those headers only

Following from the answer to this question:
SQLite Select data where the column name contains a string?

I would like to know how to create a table with these new columns obtained from the previous table. I wrote something like this (Please ignore the WHERE statement):

CREATE TABLE new_table
AS(
SELECT name
FROM pragma_table_info("old_table")
WHERE name NOT LIKE '%%%' ESCAPE ''
FROM old_table
);  

however, it is not working. Any help in this direction would be much appreciated. Many Thanks

Advertisement

Answer

If you want all the columns of old_table then you can do it like this:

create table new_table as
select * from old_table
where 0;

If you want specific columns you must specify them on the select list:

create table new_table as
select col1, col2, ... from old_table
where 0;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement