/ Published in: MySQL
MySQL Insert Unique Reference using MAX() to obtain latest value Alternate solution to using Composite Primary Keys which INNODB engine does not support.
Expand |
Embed | Plain Text
INSERT INTO jobs (companyid,clientref,jobid) VALUES (8,2,IFNULL((SELECT max(b.jobid)+1 FROM jobs b WHERE b.clientref=2),1) );
You need to login to post a comment.
