I have two table such as table1 and table2. Below shows the following sample fields:
table1 : id, amount
table2 : id, total_amount
I want to insert a value to my table2 using an insert query. But the problem is I want one of the values of my insert query to be the result of a subquery inside an insert statement. For example:
INSERT INTO table2(id, total_amount) VALUES(111, (SELECT SUM(amount) from table1 WHERE id=1));
I knew that the above query is wrong. How can I do the query that can be able to insert to table2 where one of the value to be inserted to table2 is the resulting query from my table1 as shown above?
Can anyone help me with this? Thanks
INSERT INTO table2(id, total_amount)
SELECT 111, SUM(amount) from table1 WHERE id=1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments