Progresstable hasprogressId,lessonIdanduniqueIdTestResultstable hasprogressIdTestResultstable now haslessonIdanduniqueId
This SQL statement foreach progrssId in TestResults will get lessonId and uniqueId from Progress:
select progressId,
(select lessonId from Progress p where p.progressId = TestResults.progressId) as lessonId,
(select uniqueId from Progress p where p.progressId = TestResults.progressId) as uniqueId
from TestResults
where progressId is not null;
Now I want to update lessonId and uniqueId in TestResults table foreach associated progressId. I need foreach idea. I don’t know how to do that in SQL.
Advertisement
Answer
You need to join the 2 tables in the UPDATE statement:
update TestResults t
inner join Progress p on p.progressId = t.progressId
set t.lessonId = p.lessonId,
t.uniqueId = p.uniqueId