这是我试图在 MySQL 中找出的问题。我们有一个旧表,其中包含我们用户提交的一些表单。不知何故,之前的决定是每次用户参与此调查时,都会提交一个新表单。因此,在旧表中,我们很容易有几行具有相同的名字和姓氏,但其他列中的值不同,并且还有一个时间戳列 Date_Submission。
现在我们正在尝试将所有内容移动到一个新表中,但这一次,对于每个人,我们只保留一行。我们希望保留该用户的一些最新旧数据(如电子邮件、电话号码等)
我可以执行以下操作:
update newtable, oldtable set newtable.email = oldtable.email where newtable.firstname = oldtable.firstname and newtable.lastname = oldtable.lastname;
显然,这不会给我每个人的“最新”旧日期。
所以我尝试了这个:
update newtable, oldtable set newtable.email = oldtable.email where newtable.firstname = oldtable.firstname and newtable.lastname = oldtable.lastname 按 oldtable.Date_Submission 顺序;
但是他们 MySQL 会抱怨:
“错误 1221 (HY000):UPDATE 和 ORDER BY 的错误使用”。
所以我想知道,实现这一目标的正确方法是什么?