I have a table product_pushjobs with 5 columns: id, user, product, connection, done`
ID is primary and auto increment.
For insert, I only fill in user and product (sometimes connection, depending on situation)
I want to prevent the insert when there is an other row with user and product, but only if done IS NULL.
So the table can have a million rows of the same user and product, but not when there is one that has a done is NULL .
I found a lot different suggestions here on this site, but not exactly the same as mine. I've tried this, but have me an error:
INSERT INTO product_pushjobs (user, product)
VALUES (5,9936)
WHERE NOT EXISTS (
SELECT id FROM product_pushjobs
WHERE user=5 AND product=9936 AND connection IS NULL AND done IS NULL
)
mysql error:
#1064 - 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 'WHERE NOT EXISTS (SELECT * FROM product_pushjobs WHERE user=5 AND product=9936 A' at line 1
I'm guessing it will be a stupid problem, but one that I need to fix fast.
(5,9936).