Inserting into a Table with Selective Values and Defaults
Searching for a solution to insert data into one table while selecting specific values from another table and incorporating some default values can lead to challenges. You may encounter errors such as "mysql error" or "column count does not match."
To resolve this, consider the following structure for your INSERT statement:
INSERT INTO def (catid, title, page, publish) SELECT catid, title, 'page','yes' from `abc`
This updated query accomplishes the desired outcome by explicitly listing the values to be inserted into the def table. The catid and title values are selected from the abc table, while the page value is set to 'page' and the publish value is set to 'yes' as default values.
By adhering to the correct syntax, you can successfully insert data into your table while utilizing values from both the source table and default values.
The above is the detailed content of How to Insert Data with Selective Values and Defaults in MySQL?. For more information, please follow other related articles on the PHP Chinese website!