Inserting Data with Default Values Using Nested SELECT
Inserting data into a MySQL table from another table while assigning default values to certain columns can be achieved using a nested SELECT statement.
In the provided queries, the first one encounters an error because the column list in the main INSERT statement does not match the number of columns returned by the subquery. The second one generates a column count mismatch error because the main INSERT statement specifies four columns, while the VALUES() clause only provides three values.
To rectify this issue, use the following syntax:
INSERT INTO def (catid, title, page, publish) SELECT catid, title, 'page','yes' from `abc`
In this modified query:
The above is the detailed content of How to Insert Data with Default Values Using Nested SELECT Statements in MySQL?. For more information, please follow other related articles on the PHP Chinese website!