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 6858789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:12:11+00:00 2026-05-27T02:12:11+00:00

These are actually two questions relating to an online bookstore. I have a table

  • 0

These are actually two questions relating to an online bookstore.

I have a table for customers in SQL, and it has all this customer info, including a customer ID. Then I have a table full of books on sale. Lastly, I have a table for a shopping cart.

Now the shopping cart is going to be a table very similar to the books table, only it will have less items since it’ll contain some subset of the book table’s contents.

I want the entire cart to be tied to a single customer’s ID, and I want every entry in that cart to come directly from the Books table.

How to I go about defining such a table, I mean what statements do I need?

As it is, I’m confused about the issue, because the entire cart table essentially an attribute of a single customer, but I have no idea how to represent that in SQL. I want to be able to look up the cart table using the customer ID, basically.

Any help would be greatly appreciated.

  • 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-27T02:12:12+00:00Added an answer on May 27, 2026 at 2:12 am

    You basically need these four tables:

     create table books (book_id int, name varchar(200), author(200));
     create table customers (customer_id int, name varchar(200));
     create table carts (cart_id int, customer_id int);
     create table cart_details (cart_id int, line_number int, book_id int, qty int, price numeric(18,2));
    

    In essence, you will store objects like this:

    1. Books into books table
    2. Customers into customers table
    3. Carts into carts and cart_details table. carts will represent a cart for a certain customer, and cart_details will represent cart’s content.

    Whenever you want to retrieve a cart corresponding to a certain customer you can just do:

    select * from carts inner join customers using (customer_id);
    

    If you also want cart’s detail you can do:

    select * from carts 
    inner join cart_details using (cart_id)
    inner join customers using (customer_id)
    ;
    

    Note: Tried to write examples in a as general as possible SQL syntax since you didn’t provide the RDBMS you are using. Also, left out on purpose all details related to primary and foreign keys so you can understand tables and their attributes first.

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

Sidebar

Related Questions

I have a database that has two tables, these tables look like this codes
Actually I have two questions. (1) Is there any reduction in processing power or
I have these two statements : printf(%u,a+1); and printf(%u,(int *)a+1); Actually I was working
I actually have two questions, I found the answer to the second and didn't
Okay, so this is actually two questions. First, I want to know if there
Looking at similar questions, I actually want the exact opposite of this: SQL query
This post is actually divided in two questions: Which kinds of associations classes/interfaces usually
Actually, I have two related questions. I'm capturing filtered network traffic by libpcap on
Actually, in my app, I have created a graph using achartEngine . In these
I've spent two days on this and have gotten nowhere. I'm trying to use

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.