Topic: a variable in UPDATE
All greetings. And all I congratulate on holidays. Now to business.
There are two tables:
Tab1 With fields: id1, nom
Tab2 With fields: id1, nom
It is necessary in Tab1 to find records corresponding id1 in Tab2, among them to find the maximum value nom and to interpose it into an appropriate line of table Tab2. And in each following record value nom should
The one who read up already to this place, the surprise in the form of remarkable, undoubtedly putting all on the places of an example waits
UPDATE Tab2, Tab1 SET Tab2.nom = (SELECT MAX (nom) FROM Tab1 WHERE Tab2.id1 = Tab1.id1) +1 WHERE Tab1.id1 = Tab2.id1;
My request everything that is necessary does, but not nom. Simply, stupidly increases it on 1. That is even finding for example three records and Max (nom) =10, the request puts simply down in the field nom 11,11,11, and I want that was 11,12,13. I do not hope At all that clearly explained, but very much tried. Help friends, to solve the task.