I have a insert statement that need to get a specific value from another table.
So, I searched and found this question: How to insert values into an MYSQL-Table by using Select-Statements
However, I'm having difficult in my case, since I just need 1 column.
What I have right now:
INSERT INTO TABLE_A (ID_STATUS, ID_USER, ID_Q_INI, ID_Q_FIN, PRICE )
VALUES
(1, 2, 10, 17, (SELECT SUM(PRICE) FROM TABLE_B WHERE (ID_Q >= 10 && ID_Q < 17))
What I want to do is: when I register a new purchase, my script only will input the status, user id, and both initial product id, and final product id.
The final price will be the sum from the products from X to Y-1.
Is what I'm trying to do even possible? Or I'll have to make a first query, to get the value and then make the insert?