How to increase or decrease value to another table?

How to increase or decrease value to another table?



I have two tables - bags and market.
enter image description here



At this time, in the bags table has data like :
enter image description here



If I add data from the market table, the qty column in the table bag will decrease according to the amount inputted in the market table. And the total price column will calculate the total_qty (market) * price (bags)





Seems like you want to store values calculated from other columns? That's generally a bad idea, too much risk of data inconsistency. Consider views or computed columns instead. (Or manage using triggers.)
– jarlh
Aug 30 at 8:10





really? can you give me any solution how to solve this problem?
– Kusnadi
Aug 30 at 8:14





You need to provide sample data and desired results. Your explanation is not as clear as you think it is. By the way, the answer to your question is that you need a trigger.
– Gordon Linoff
Aug 30 at 11:09




1 Answer
1



From My Understanding I suggest for this concept to use Trigger,


DELIMITER $$
CREATE TRIGGER trg_insert
AFTER INSERT ON market

begin
update bags set qty = ((select qty from bags where id=1)-(select
market.total_qty from market where
id=1) ))
,price = ((select price from basgs where id=1)-(select market.total_prc
from market where
market.id=1)))
where bags.id = 1;
END$$
DELIMITER $$



Now i am using with static values which you are provided,
Try this code.





it's error sir.. 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'begin update bags set qty = (bags.qty-(select market.total_qty from market whe' at line 4'
– Kusnadi
Aug 30 at 22:14



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)