I have seen similar questions to mine, however nothing seems to fit the scenario exactly.
I have 2 tables, bills and accounts.
If a bill is pushed into the bills table and there is not already an account, I want to create a record in the accounts table.
I have:
...
BEFORE INSERT ON bills
FOR EACH ROW
BEGIN
INSERT INTO accounts (id, field1, field2, field3, field4)
SELECT accountID, 'value1', value2, value3, value4
FROM bills
WHERE ((SELECT LEFT(accountID, 5) = 'XXXXX' |
(SELECT LEFT(accountID, 5) = 'XXXXX' |
(SELECT LEFT(accountID, 5) = 'XXXXX' |
(SELECT LEFT(accountID, 5) = 'XXXXX' |
(SELECT LEFT(accountID, 5) = 'XXXXX')) &&
accountID NOT IN (SELECT id from accounts); ## I know this line is not right
END$$
From What I have read elsewhere on SO my options seem to be ON DUPLICATE KEY UPDATE or INSERT IGNORE, neither of which I can seem to make work, nor can I find an example with INSERT, SELECT, FROM and WHERE all involved.
What am I missing?
EDIT: I can make it insert the record, but depending on how I have tried it I always get either "duplicate id" error, or it doesnt insert the record.