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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:35:52+00:00 2026-06-13T08:35:52+00:00

I have a table (Order_line_t) with the following format: Order_ID Product_ID Quantity ——– ———-

  • 0

I have a table (Order_line_t) with the following format:

Order_ID    Product_ID    Quantity
--------    ----------    --------
1001        1             2
1001        2             2
1001        4             1
1002        3             5
1003        3             1
1004        6             2
1004        8             2
1005        4             4
1006        1             1
1006        5             2
1006        7             2
1007        1             3
1007        2             2
1008        3             2
1008        8             3
1009        4             2
1009        7             3
1010        8             10

My goal is to show the total quantity that has been ordered by descending popularity for each product like this: (I used my current query and clicked on Descending Filter for Column Total_Quantity to achieve this result)

Product_ID    Total_Quantity
----------    --------------
8             15
4             8
3             8
7             5
1             5
2             4
6             2
5             2

I have been trying to figure this out for 3 hours, and I don’t know where I my error is. My current SQL Query is this:

SELECT  Product_ID, SUM(Quantity) AS Total_Quantity
FROM Order_line_t
GROUP BY Product_ID

My Query result is this:

Product_ID    Total_Quantity
----------    --------------
1             5
2             4
3             8
4             8
5             2
6             2
7             5
8             15

Thanks in advance, I am just beginning to learn SQL. Please bear with me.

  • 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-13T08:35:54+00:00Added an answer on June 13, 2026 at 8:35 am
    SELECT  Product_ID, SUM(Quantity) AS Total_Quantity
    FROM Order_line_t
    GROUP BY Product_ID
    ORDER BY SUM(Quantity) DESC;
    

    OR

    SELECT Product_ID, Total_Quantity
    FROM
    (
        SELECT  Product_ID, SUM(Quantity) AS Total_Quantity
        FROM Order_line_t
        GROUP BY Product_ID
    ) SQ
    ORDER BY Total_Quantity DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: Order Product Price Quantity Description Order1 Product1 12 1
I have the following Mysql Table Order table status 0 - incomplete status 1
Having a problem with the following Query. i have a device table which logs
I have a table with the following structure: id, Metal, AmPm, GBP, USD, EUR,
I have a table: Order Detail. An Order has many details, in my case
I have a table called order which contains columns id , user_id , price
Let's say I have an Order table which has a FirstSalesPersonId field and a
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
Let's say we have a Product table, and Order table and a (junction table)
Related to - PostgreSQL DISTINCT ON with different ORDER BY I have table purchases

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.