I'm trying to write a query. Here's what my table layout looks like:
Code:
TOCID PROP_ID STR_VAL
1 1 Yes
1 2 No
2 1 Yes
2 2 No
3 2 Yes
4 1 Yes
4 2 No
Basically, I need to insert a row with a prop_id = 1 for each tocid that does not have one. I have this, but it doesn't work. I don't know if I should be using NOT EXISTS or not.
Code:
INSERT INTO propval (tocid, prop_id, pos, str_val)
VALUES (tocid, 1, 0, 'No')
WHERE NOT EXISTS (SELECT * FROM propval WHERE prop_id = 1)
Thanks!