Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4254538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:05:51+00:00 2026-05-21T05:05:51+00:00

If I am building a multi-shop e-commerce solution and want the orders table to

  • 0

If I am building a multi-shop e-commerce solution and want the orders table to maintain a shop based sequential ID, what is the best way of doing this?

For instance imagine these order IDs in sequence: –

UK0001  
UK0002  
UK0003  
DE0001  
UK0004  
DE0002  

etc.

  1. through grouped PK ID MySQL / MyISAM

    • MySQL will manage this automatically if a country field and
      an auto incrementing ID field are
      used. But MyISAM has some inherent
      problems such as table locking and
      this feature seems like it’s feature
      that is only available in MyISAM so
      moving database engine would not be
      possible with this solution.
  2. Programmatically. Let’s say we have
    two fields: order_id (global auto
    inc PK column managed by DB),
    order_number (country specific
    sequential ID field maintained
    through code) and the table also has
    a shop_id column to associate orders
    to shops.

So – after the new order record has been created and the DB engine has assigned an ID to the new record, and the newly created order ID has been retrieved in code as variable $newID

select order_number+1 as new_order_number from orders where order_id < $newID and shop_id = UK order by order_id desc limit 1

(this is pseudo code / sql btw)

Questions:

  1. is this a feasible solution? Or is there a better more efficient way to do this?

  2. When the table has 1 million + records in it, will the additional query overhead per order submission cause problems, or not?

  3. It seems there’d be a chance of order_number clashes if two orders are placed for the same country and they get processed simultaneously. If this a possibility? if so, is there a way of protecting against it? (perhaps a unique index and a transaction?)

Look forward to your help!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:05:52+00:00Added an answer on May 21, 2026 at 5:05 am

    Yes you are definitely on the right track. Set the ORDER ID field as UNIQUE and do the exact same thing you were trying to do. Add a catch statement where if it is not added because of the UNIQUE error, then try to insert it again with the same statement to ensure that the ORDER ID is never inserted with the same ID at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building on this question , is there a simple solution for having a multi-key
I have a problem with building multi level select box. I have category table
We are building a multi-tenant server with a database/schema per tenant. To do this
Need just a push in the right direction with this. I'm building a multi-language
I'm building multi tenant application with shared table structure using Microsoft SQL Server. I
I am building a multi language site I have a descriptions table that hold
I am building a multi-language site using codeigniter I have this language file $lang['prot_home_1']
I'm building an app based on jQuery mobile, and using the multi-page template feature
I am building a multi-site platform, similar to StackExchange in the way that it
Hi we are building an multi tenancy solution where each tenant will have its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.