Inserting Values from Another Table with Default Values in MySQL
You want to insert data into a table named def by selecting specific values from another table named abc. Additionally, you want to include some default values in the insertion.
The syntax for inserting values into a table while selecting from another table and including default values is as follows:
INSERT INTO target_table (column1, column2, ..., columnN) SELECT column1, column2, ..., columnM, default_value1, default_value2, ... FROM source_table
In your case, you can insert data into the def table by executing the following query:
INSERT INTO def (catid, title, page, publish) SELECT catid, title, 'page', 'yes' FROM abc
Ensure that the number of columns in the SELECT clause matches the number of columns specified in the INSERT statement.
The above is the detailed content of How to Insert Data with Default Values from Another Table in MySQL?. For more information, please follow other related articles on the PHP Chinese website!