I have to insert data into a table with the following pattern
INSERT INTO tablename (a, b) VALUES (
(123, (SELECT foo FROM someothertable WHERE some_condition)),
(456, (SELECT foo FROM someothertable WHERE some_condition)),
(789, (SELECT foo FROM someothertable WHERE some_condition)),
...
All inserted rows have the same value for the b column and I want to factor it out. I could manually perform the subselect and paste the value in, but that will break encapsulation in the set of scripts I’m writing.
Can I do this in pure SQL within the same query?
1 Answer