Best Approach to Generate Unique Order Number with concurent inserts in Sales Application - Mysql/PHP
<p>We have a sales application where we are generating a unique order number by adding increment in the previous value. Since we are using unique combination based on the orderid and store id, we can not use auto increment. However sometime we are getting duplicate order ids if request is submitted from multiple client devices. </p>

<p>Can you please advise the better way to handle an order id generation based on order id and store id? We are using PHP as scripting language.</p>

<p>This is what we have as of now.</p>

<pre><code>// Table Structure

salesorders (Order_id, store_id)

$generatenextorderid = "select max(order_id) + 1 from salesorders where store_id = 1";
</code></pre>

<p>Any suggestions?</p>