I need to insert into a table (groupL) two rows (custId, aName). custId is constant while aName is multiple records of variable size based on a nested subquery.
That subquery is:
SELECT aName
FROM artwork
WHERE artwork.title IN (SELECT title
FROM classify
WHERE NEW.g_name = classify.g_name);
I’ve tried a lot of SQL but I really don’t get it. I’m looking for something that if we have two rows in aName (name1, name2) it’ll do something like
INSERT INTO groupL(custId, aName)
SELECT custIdConstant, name1
WHERE NOT EXISTS (SELECT custIdConstant, aName
FROM groupL
WHERE custId = custIdConstant AND aName = name1);
INSERT INTO groupL(custId, aName)
SELECT custIdConstant, name2
WHERE NOT EXISTS (SELECT custIdConstant, aName
FROM groupL
WHERE custId = custIdConstant AND aName = name2);
How do I do this? Any guidance would be appreciated.
2
Answers
You can do in one Go but you need to have the ids before hand, if you want to compare and of course a FROM clause
fiddle
I think you just want to check for the existence of those rows via a second subquery:
You might want to check into merge as well.