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

  • Home
  • SEARCH
  • 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 6551213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:18:31+00:00 2026-05-25T12:18:31+00:00

I have a table Orders. Each order can have the same product multiple times.

  • 0

I have a table Orders. Each order can have the same product multiple times. Quantity is not enough as each product may have different preferences!
So i am wondering what is better to do…

PK-id order id product id ? Primary key is PK-id

or
Orders Table
(Order-id ,orderline) as PK..

Then another table
Orderlines
(Order-id, orderline, productid) as PK

And then
OrderLinesPreferences
(Order-id ,orderline, productid, preferenceid )as PK ?

I wonder whether this approach is ok .Also i dont know what i should i do about indexing in order not to get slow when records are many. I am using postgresql..
For example in table OrderLinesPreferences a where order-id=1 and productid=10; would be fast or would do a full table lookup ?

  • 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-25T12:18:32+00:00Added an answer on May 25, 2026 at 12:18 pm

    Based on a comment made by @OP to an answer by dnuttle, I would say the situation calls for items and sub-items, all from a list of basic items.

    So:

    PRODUCT
      product_id PK
    , description
    , ...
    
    OPTIONAL_ITEM
      option_id PK
    , description
    , ...
    
    ORDER
      order_id PK
    , date_taken...
    
    ORDER_ITEM
      order_id PK, FK
    , item_number PK     // Or use a surrogate as PK, if you like
    , product_id FK
    , quantity
    
    ORDER_ITEM_OPTION
      order_id PK, FK
    , item_number, PK, FK  // Order and item FK to ORDER_ITEM
    , option_id, PK, FK    // FK to OPTIONAL_ITEM
    , quantity
    

    This gives you what you need to have an order with the same item multiple times and 0 or more options applied to each item, as in a coffee with different amounts of cream and sugar etc. as per OP’s requirement.

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

Sidebar

Related Questions

I have a table products and table sizes. Each product can have multiple sizes.
In MS Transact SQL, let's say I have a table (Orders) like this: Order
I have a table which contains sales order data (order number, product number, sales
Each 'Product' can have as many as 10000 'Segment' rows. The segments have a
Each product in my database can have at least three and sometimes four or
I have a Vote-scoring system, each user can score any product each day (maximum
I have one table orders with a foreing key ProductID. I want to show
If I have a table Orders with fields CustomerID , OrderID and OrderDate ,
I have an orders table with a schema like this. CREATE TABLE orders (
I have an Orders table (simplified) OrderId, SalesPersonId, SaleAmount, CurrencyId, ... I am attempting

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.