There is a page in the online documentation that explains safe mode entitled 'safe Server Startup Script'.
Suppose you have a table where each row is associated with a certain group (For example, orders are associated with the customers placing them) where each item WITHIN the group has a distinct number (For example, each person my have a sequence of competition results - each person, therefore, has a 1st, 2nd, 3rd... If you would like to renumber items within their group so that each has the same baseline (say 0), here is an example way to proceed: Create TEMPORARY Table Groups (Id INTEGER AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(31), Group Id VARCHAR(31), Val Within Group INTEGER); INSERT INTO Groups VALUES (null, "Davy", "Boy", 2); INSERT INTO Groups VALUES (null, "Mary", "Girl", 2); INSERT INTO Groups VALUES (null, "Bill", "Boy", 5); INSERT INTO Groups VALUES (null, "Jill", "Girl", -3); INSERT INTO Groups VALUES (null, "Fred", "Boy", 3);# Find the lowest value for each group CREATE TEMPORARY TABLE Group Sum AS SELECT Group Id, MIN(Val Within Group) AS base Val FROM Groups GROUP BY Group Id;# create an index so my SQL can efficiently match ALTER TABLE Group Sum ADD UNIQUE (Group Id);# finally, make the baseline adjustment UPDATE Groups LEFT JOIN Group Sum USING (Group Id) SET Val Within Group=Val Within Group-base Val; SELECT * FROM Groups;# 1 Davy Boy 0# 2 Mary Girl 5# 3 Bill Boy 3# 4 Jill Girl 0# 5 Fred Boy 1#Each group ("Boy", "Girl") now has a (lowest) Val Within Group entry of 0.
Here is the closest I could come up with for doing that on Oracle:update t1 set t1.field=(select value from t2 where t1.this=t2.that) where t1in (select that from t2); That strikes me as convoluted by comparison.
order by recno desc limit 1You can also accomplish the same by the following query :update t1 , (select id ,max(recno) as recno from t1 where id=8 group by recno) ttset t1.c1 = ' NO'where tt.id=t1and t1.recno=tt.recno Comments are welcome.
Adam Boyle's commment above was just what I was trying to do, update one table based on a relationship between that table and another.
(Bug #11758262, Bug #50439) See Section 220.127.116.11, “Determination of Safe and Unsafe Statements in Binary Logging”, for more information.That's how you can do ittable busstopsid | route | busstop | pos1 | 1 | A | 1 2 | 1 | B | 2 3 | 1 | C | 3 4 | 2 | C | 1 5 | 2 | D | 2 6 | 2 | A | 3 7 | 2 | E | 4 8 | 2 | F | 5 9 | 2 | G | 610 | 2 | H | 7Moving D, E, F, G To route 1 SET @pos=(SELECT max(t1.pos) FROM busstops t1 WHERE t1.route = 1 ); UPDATE busstops SET pos = ( SELECT @pos := @pos 1 ), route =1 WHERE id IN (5,7,8,9)I doubt this could be done otherwise since referencing the table you wish to update within the subquery creates circular references After DELETE or UPDATE i.e.when a row of a subset is lost/deleted/moved away from it, the whole subset will need to be reordered.Notes: That index addition is necessary because on larger tables my SQL would rather die than figure to (internally) index a single column join.I was not able, using my SQL 4.1.1, to do this as a subquery: UPDATE Groups LEFT JOIN (SELECT Group Id, MIN(Val Within Group) AS base Val FROM Groups GROUP BY Group Id) AS Grp Sum USING (Group Id) SET Val Within Group=Val Within Group-base Val; Csaba Gabor UPDATE Syntax with "on-line" updating value limitations.