How to write insert query using select query?
In SQL, the INSERT INTO statement is used to add or insert data into a specific table. It can also be used to add data from one or more tables. In the normal scenario, we use the VALUES keyword with the INSERT INTO statement. However, instead of the VALUES keyword, we can use the SELECT statement to add one or more records from the table. The SELECT statement can be used along with the WHERE clause to fetch specific records.
--:::SYNTAX:::--
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
INSERT INTO users_copy( id, name, phone )
SELECT user_id, user_name, user_phone
FROM users
WHERE age = 30;