Every puzzle has an SQL query
Aug. 13th, 2010 03:17 pmUPDATE lcmr.content_relationship SET content_entity= ( SELECT TOP 1 ce_id FROM lcmr.content_w_xms_name newContent WHERE newContent.content_type=130 AND newContent.xms_name='Badger Mushrooms' ) WHERE id IN ( SELECT lcmr.content_relationship.id FROM lcmr.content_w_xms_name newContent, lcmr.content_relationship INNER JOIN lcmr.property_value ON (lcmr.content_relationship.id=lcmr.property_value.id) WHERE property=13 AND lcmr.property_value.content_instance NOT IN ( SELECT pvForExisting.content_instance FROM lcmr.property_value pvForExisting, lcmr.content_relationship crForExisting WHERE pvForExisting.id = crForExisting.id AND pvForExisting.property = 13 AND crForExisting.content_entity IN ( SELECT TOP 1 ce_id FROM lcmr.content_w_xms_name newContent WHERE newContent.content_type=130 AND newContent.xms_name='Badger Mushrooms' ) ) AND (newContent.content_type=130 AND newContent.xms_name='Badger Mushrooms') AND content_entity IN ( SELECT TOP 1 ce_id FROM lcmr.content_w_xms_name oldContent WHERE (oldContent.content_type=130) AND oldContent.xms_name='Cow Exploding' ) ) ; DELETE FROM lcmr.property_value WHERE id IN ( SELECT pv.id FROM lcmr.property_value pv, lcmr.content_relationship cr WHERE pv.id = cr.id AND property=13 AND content_entity IN ( SELECT TOP 1 ce_id FROM lcmr.content_w_xms_name oldContent WHERE (oldContent.content_type=130) AND oldContent.xms_name='Cow Exploding' ) ) ;
A masterpiece. (This is just one of them - it has to do all this about 32 times for different locations.)
Note the fair amounts of repetition - SQL is not my strong point, and this probably does things 100 times slower than they could be. It might be possible in about four lines, I don't know.
Note the fair amounts of repetition - SQL is not my strong point, and this probably does things 100 times slower than they could be. It might be possible in about four lines, I don't know.