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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:37:05+00:00 2026-06-14T15:37:05+00:00

I m try to make a select from one table based on register of

  • 0

I m try to make a select from one table based on register of a second table

i m using 4 tables

table Products
Product_Id     |  Product_Name    |   Product_Value   | Category_Id
1              |  Ball            |   10              | 1
2              |  Pen             |    2              | 2 
3              |  Eraser          |    1              | 1

table Categories
Category_Id    |  Category_Name
1              |  Acessories
2              |  Others

table Customers
Customer_Id    |  Customer_Name
1              |  John
2              |  Peter

table Sells
Sell_Id        |  Product_Id      |   Customer_Id   |  Sell_Date
1              |  1               |   1             |  2012-01-01
2              |  2               |   1             |  2012-01-02

So i want to make a select to show on customer historic what he buy

like

John Historic

Product Name  Category Name   Date
Ball          Accessories     2012-01-01
Pen           Others          2012-010

On final i am showing information form 3 different tables

I have try using INNER JOIN and LEFT JOIN but with no success.

Thanks for any help.

  • 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-06-14T15:37:07+00:00Added an answer on June 14, 2026 at 3:37 pm

    Break it down: THe first thing you want is a Product Name:

    SELECT Product_Name FROM Products
    

    How do we get the category? Join it in!

    SELECT Products.Product_Name, Categories.Category_Name 
    FROM Products JOIN Categories ON Products.Category_Id = Categories.Category_Id
    

    Getting close! Time to bring in the order history:

    SELECT Products.Product_Name, Categories.Category_Name, Sells.Sells_Date 
    FROM Products 
    JOIN Categories ON Products.Category_Id = Categories.Category_Id
    JOIN Sells ON Sells.Sells_Id = Products.Product_Id
    

    Now we can bring in the name, and filter to John:

    SELECT Products.Product_Name, Categories.Category_Name, Sells.Sells_Date 
    FROM Products 
    JOIN Categories ON Products.Category_Id = Categories.Category_Id
    JOIN Sells ON Sells.Sells_Id = Products.Product_Id
    JOIN Customers ON Sells.Customer_Id = Customers.Customer_Id
    WHERE Customers.Customer_Name = 'John'
    

    Just take it one step at a time in your mind. Build the query from each part as you go.

    Since you mentioned it…

    LEFT JOIN is how you deal with missing data. It returns rows from the “left” table, and puts NULL in the fields of the “right” table if there is no match for the ON clause.

    For example, if John bought a Product with no category (Product.Category_Id was NULL), using a JOIN would not return that record of purchase because there was no matching Category with Category_Id Null. In that case, you could LEFT JOIN Categories and in the result set, Category_Name would be NULL as well.

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

Sidebar

Related Questions

I have two tables. I try to select some records from one of them.
Using the following query to select data from a table in 15 minute intervals
I try to make a table header fixed when scoll down on pages. The
Using mysql (and php) I try to hide out of a select menu category's
There are thee tables inside my database. One is employee , the second is
I have a simple databse that I'm using to try to make a job
I am using a tpl system with smarty, when I try to make a
I'll try to make this clear. I need to select a specific row and
I am working a sample application using Windows Azure table storage. I will try
I have 2 tables : Item and Location (one - many ). I select

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.