I am trying to create an SQL query wherein I need to check to sum of columns from 2 tables and then insert a new row into another table if the condition is satisfied. I know I can use a stored procedure with explicit locking but want to know is it is possible to do it in a single SQL query. I wrote the following but it gives syntax error in MySQL workbench
INSERT INTO table1 (`col1`, `col2`)
VALUES ('abc', 'xyz') WHERE
(
((select
COUNT(*) from table2 t2 where t2.id = 1)
+ (select sum(t3.counter) from table3 t3
WHERE t3.id = 1)) < (select t4.total_allowed
FROM table4 t4 where t4.id = 1)
);