I need to make a subquery in a large query, but am unsure on how to implement this with many other predefined values involved. Lots of examples just show 2 rows that are both obtained trough the subquery.
Can anyone explain to me how to check for the last 'ordernummer' add that with +1 and use that value in the insert query?
INSERT INTO orderheaders (user, timestamp, ipadres, ordernummer, ordernummer_cash, offertenummer, debnr, contact, referentie, quantity, totaal, paymethod, shipmethod, paymentkey, bank_id)
VALUES ('".$user."', '".time()."', '".$_SERVER['REMOTE_ADDR']."', '".$ordernummer."',$ordernummer,'".$_POST['offertenummer']."','".$newdeb."', '".$newcontact."', '".$_POST['referentie']."', '".$total_qty_prods."', '".$totaal."', '".$paymethod."', '".$shipping."', '".$paymentkey."', '')
so for $ordernummer I need to get the value of
SELECT ordernummer FROM orderheaders ORDER BY id DESC LIMIT 0,1
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `orderheaders` ADD INDEX `orderheaders_idx_id` (`id`);
SELECT
orderheaders.ordernummer
FROM
orderheaders
ORDER BY
orderheaders.id DESC LIMIT 0,
1