MySQL Forums
Forum List  »  Newbie

Re: Updating a field by the order of onother...
Posted by: Felix Geerinckx
Date: May 27, 2005 04:13AM

Roberto Cano Ramos wrote:

> I need to update the whole table. Seetting the field ORDER_NUM to the position of the order by
> ID_MEMBER

USE test;
DROP TABLE IF EXISTS control;
CREATE TABLE control (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
member_id INT NOT NULL,
order_num INT NOT NULL DEFAULT 0
);

INSERT INTO control (member_id) VALUES
(1), (5), (2);

SELECT * FROM control;

SET @t := 0;
UPDATE control
SET order_num = @t := @t + 1
ORDER BY member_id;

SELECT * FROM control;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: Updating a field by the order of onother...
May 27, 2005 04:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.