I have a scenario in which when i update a record the query should update the max(id_inc) + 1 from the table 'Process'. Next it needs to update another field inv_id_inc in the same table 'Process' with a simple concat function (SELECT CONCAT(max(inv_id) , '/', 16). That is it should update as 1/16, then 2/16, then 3/16 etc. 16 is the current year short form. I am not sure if i can achieve this in one query. At present i tried with 2 queries. First query it updates max(id_inc) + 1 and second query it concatenate CONCAT(max(inv_id) , '/', 16. Iam not sure if iam doing correct.
================================
tender_id | id_inc | inv_id_inc
================================
200 | 1 | 1/16
300 | 2 | 2/16
My First Query is below:.
update process
set inv_id=
SELECT MAX( inv_id ) + 1 FROM process where tender_id=200;
My second query is below:
update process t
join (SELECT CONCAT(max(inv_id) , '/', 16) as inv_id_inc
from process ) t1
set t.inv_id_inc=t1.inv_id_inc WHERE tender_id='200'";
Its not updating. Can anyone suggest me a solution please.?
Now its working. I changed 2 queries. The updated queries are below:
FIRST QUERY:
UPDATE process set inv_id = ((SELECT inv_id FROM (SELECT MAX(inv_id) AS inv_id FROM process)
AS inv_id_new) + 1) WHERE tender_id='200'
SECOND QUERY:
update process t
join (SELECT CONCAT(max(inv_id), '/', 16) as inv_id_inc
from process ) t1
set t.inv_id_inc=t1.inv_id_inc WHERE tender_id='200'
Is there a better solution?