Frequently asked questions - Base
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
How can I create a table using a SELECT statement?
You can create a table using a SELECT statement from the Utils > SQL menu by executing a command like
SELECT "FieldName" [ ,... ] INTO CACHED "NewTable" FROM "SourceTable" [ WHERE <expression> ]
One could, for example, create a new table from this selection:
The SQL selection to use to create the new table is:
SELECT "ID_Table","Nom","DateNaissance" FROM "Table1" WHERE "Nom" LIKE 'D%'
To create the table, execute the selection via the Utils > SQL menu
Note
- The new table is not immediately saved as a table object: execute the command "File > Save tables" (this option is only available when table objects have been created.
- The new table will be, by definition, the result of the SQL statement with all the limits pertaining to that: notably no creation of primary key.
- This is the reason that the SQL selection above doesn't include the primary key field ID_TABLE.
- If an autogenerating primary key is required for the new table it can be created by editing the table to add the field.
- If the key doesn't need to be autogenerating it can be included in the SELECT.