If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I am guessing this is an extension of your other post but I will answer in this one.

Code:

-- The below SQL inserts the userid, attribute id 33 and the month value for
-- all fields where the userid exists as having a row with attributeid 14
-- but not previously having a row with attributeid 33 (which is what you
-- want to add)
-- NOTE: If you want the name of the month you can use the function
-- MONTHNAME() instead
INSERT INTO attributes a (userid,attributeid,value)
SELECT a2.userid,33,MONTH(value) FROM attributes a2
WHERE a2.userid in (SELECT a3.userid FROM attributes a3 WHERE attributeid = 14) AND NOT a2.userid IN (SELECT a4.userid FROM attributes a4 WHERE attributeid = 33)
-- The below SQL inserts the userid, attribute id 33 and the day value for
-- all fields where the userid exists as having a row with attributeid 14
-- but not previously having a row with attributeid 33 (which is what you
-- want to add)
INSERT INTO attributes a (userid,attributeid,value)
SELECT a2.userid,34,DAY(value) FROM attributes a2
WHERE a2.userid in (SELECT a3.userid FROM attributes a3 WHERE attributeid = 14) AND NOT a2.userid IN (SELECT a4.userid FROM attributes a4 WHERE attributeid = 34)

Insert ignore, or where not exists, or where not in.... the same to someone who doesn't care about performance. Archies query makes less sense to me in terms of reading it, but it makes more sense in terms of performance.

Either way, I'd still create that index. Also I don't know how well DAY() and MONTH() will work on a column that isn't the date type (never tried).