Stut wrote:

insert into test1 set p = 2, q = (select max(q) + 1 from test1 as tmp where p = 2)

Probably not very efficient, but it works.

-Stut

Auto increment is much easier to do. If your primary key is made up of two fields and one of them is Auto Increment, then it will have the desired behavior, just do this experiment and see....

CREATE TABLE  `t` (
`p` int(10) unsigned NOT NULL default '0',
`q` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY  (`p`,`q`)
) ;

INSERT INTO `t` (`p`,`q`) VALUES
(1,NULL),
(1,NULL),
(1,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(3,NULL),
(3,NULL);

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm";

Ham Radio Repeater Database.
http://hrrdb.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to