我有三张桌子: survey,survey_invites和old_survey_invites。
我将old_survey_invites迁移到survey_invites,但在survey_invites中创建了一个名为survey_id的列,该列应与'surveys.id'相关联。
对于survey_invites.survey_id中的所有记录,我目前的插入值为1。
如何更新survey_invites.survey_id,以便根据survey.survey_string_key和old_survey_invites.survey_string_key以及surveys.location_id和old_survey_invites.location_id之间的相似性获取正确的survey.id值?我能够提出一个SELECT语句来证明我在某种程度上寻找的东西:
SELECT surveys.id, surveys.location_id, surveys.survey_string_key
FROM surveys
JOIN old_survey_invites
ON surveys.survey_string_key = old_survey_invites.survey_string_key
AND surveys.location_id = old_survey_invites.location_id
ORDER BY old_survey_invites.id
总之,我希望根据survey.survey_string_key = old_survey_invites.survey_string_key和surveys.location_id = old_survey_invites.location_id将survey.id放入survey_invites.survey_id。
编辑,从old_survey_invites迁移到新的survey_invites我做:
INSERT INTO survey_invites(user_id, user_invitation_id, survey_id,
invitation_date, last_modified_date, survey_link)
SELECT (user_id, user_invitation_id, 1, invitation_date,
last_modified_date, survey_link FROM old_survey_invites);
我将survey_id作为占位符放置1。