Return to Snippet

Revision: 18391
at September 29, 2009 14:00 by cherbert


Updated Code
INSERT INTO jobs (companyid,clientref,jobid) VALUES (8,2,IFNULL((SELECT max(b.jobid)+1 FROM jobs b where b.clientref=2),1) );

Revision: 18390
at September 29, 2009 14:00 by cherbert


Updated Code
// MySQL Insert Unique Reference using MAX() to obtain latest value
// Alternate solution to using Composite Primary Keys which INNODB engine does not support.

INSERT INTO jobs (companyid,clientref,jobid) VALUES (8,2,IFNULL((SELECT max(b.jobid)+1 FROM jobs b where b.clientref=2),1) );

Revision: 18389
at September 29, 2009 13:56 by cherbert


Initial Code
INSERT INTO jobs (companyid,clientref,jobid) VALUES (8,2,IFNULL((SELECT max(b.jobid)+1 FROM jobs b where b.clientref=2),1) );

Initial URL

                                

Initial Description
MySQL Insert Unique Reference using MAX() to obtain latest value
Alternate solution to using Composite Primary Keys which INNODB engine does not support.

Initial Title
MySQL Insert Unique Reference

Initial Tags
mysql

Initial Language
MySQL