DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
MySQL Insert Unique Reference
// 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) );