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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:22:30+00:00 2026-06-12T01:22:30+00:00

I have a table for products and a table for users who have bought

  • 0

I have a table for products and a table for users who have bought products. On the products table A there is site_name which determines where the products were bought.

Table B shows the users and what they have bought.

I am using the following to show a list of products bought, by site_name, grouping the product name together.

SELECT product FROM A JOIN B ON A.prod_id = B.prod_id WHERE A.site_name = 'ebay' group by A.product

Table A for products is:

prod_id
site_name
product

Table B for users is:

user_id
prod_id

What i can’t figure out is how to get the number of products bought per line.

e.g. in table A there is

prod_id    site_name    product
-------    ---------    -------
1          ebay         chair
2          amazon       desk
3          ebay         lamp

and on table b

user_id    prod_id
-------    -------
1000         1
1001         2
1002         1
1003         3

So I want to show each line where site_name is ebay and how many products were bought, order by most first like:

chair    2
lamp     1
  • 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-12T01:22:31+00:00Added an answer on June 12, 2026 at 1:22 am

    A minor change to Michael’s query.

    SELECT
        products.product,
        COUNT(users.prod_id) AS productsBought
    FROM
        A AS products
        INNER JOIN B AS users
            ON products.prod_id = users.prod_id
    WHERE products.site_name = 'ebay'
    GROUP BY products.product
    

    The above query will not return products that haven’t been bought.

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

Sidebar

Related Questions

I have a table of products which users have bought in the past. e.g.
I have a table which displays reviews written by users about products. The problem
I have a products table which contains information about products. Each products can have
I have a column in my PRODUCTS table called categories. Users can add more
I have got sql table which has 2 columns userid and products, userid is
I have three tables: 'users', 'products', and 'product_types'. The 'users' table stores all usual
suppose we have two tables users and products table users has an accountBalance column
I have a single product table with multiple fields which contain user evaluations of
I have table 'products' and I need to update 'price' field by 20% if
I have a table products , and I have columns like product_name , product_id

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.