select ci.live_revision as previous_revision, pp.caption, pp.story, cr.title, cr.description, i.height as height, i.width as width, i.image_id as image_id from cr_items ci, cr_revisions cr, pa_photos pp, cr_items ci2, cr_child_rels ccr2, images i where ci.live_revision = pp.pa_photo_id and ci.live_revision = cr.revision_id and ci.item_id = ccr2.parent_id and ccr2.child_id = ci2.item_id and ccr2.relation_tag = 'viewer' and ci2.live_revision = i.image_id and ci.item_id = :photo_id insert into pa_photos (pa_photo_id, story, caption, user_filename,camera_model,date_taken,flash, aperture,metering,focal_length,exposure_time, focus_distance,sha256,photographer) SELECT :revision_id, :new_story, :new_caption, user_filename,camera_model,date_taken,flash, aperture,metering,focal_length,exposure_time, focus_distance,sha256,photographer FROM pa_photos prev WHERE prev.pa_photo_id = :previous_revision