MySQL Insert Unique Reference


/ Published in: MySQL
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. INSERT INTO jobs (companyid,clientref,jobid) VALUES (8,2,IFNULL((SELECT max(b.jobid)+1 FROM jobs b where b.clientref=2),1) );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.