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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:20:27+00:00 2026-06-17T20:20:27+00:00

SELECT `products`.*, SUM(orders.total_count) AS revenue, SUM(orders.quantity) AS qty FROM `products` LEFT JOIN `orders` ON

  • 0
    SELECT `products`.*, SUM(orders.total_count) AS revenue, SUM(orders.quantity) AS qty FROM `products` 
    LEFT JOIN `orders` ON (`products`.`id` = `orders`.`product_id`) 
    WHERE (`orders`.`status` = 'delivered' OR `orders`.`status` = 'new') 
    GROUP BY `products`.`ID` ORDER BY products.ID DESC LIMIT 10 OFFSET 0

This is what I got. Currently it only grab the products which have any orders that are either delivered or new.

That WHERE statement is only for the correct calculation of SUM(orders.total_count) and SUM(orders.quantity) –

I would like to grab all the products, and if there is any orders for this product then it should look at that where statement to make sure that the order we grab are new or delivered.

  • 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-17T20:20:28+00:00Added an answer on June 17, 2026 at 8:20 pm

    The short answer is change WHERE to AND.

    Really, what that means is, the predicate on the “orders.status” column needs to be in the ON clause, rather than the WHERE clause.

    In your query, that predicate is doing the equivalent of an “orders.status IS NOT NULL“, which is going to “throw out” any of the NULL rows that were created by the LEFT JOIN.

    The easiest way to think of the LEFT (OUTER) JOIN is that it’s creating a dummy “orders” row to match to a “products” row, when there is no other “orders” row that matches. And that dummy row consists of all NULL values.

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

Sidebar

Related Questions

This is my query: SELECT `products`.*, SUM(orders.total_count) AS revenue, SUM(orders.quantity) AS qty, ROUND(AVG(product_reviews.stars)) as
$query = SELECT sum(o.feeship) feeship_total, (SELECT SUM(p.products_price) FROM products p left join orders_products op
select p.Id, sum(inc.Quantity) from Products p join Incomes inc group by p.Id order by
Any idea why query SELECT m.* FROM products_description pd, products p left join manufacturers
I'm trying to use the MySQL CASE statements to select products from a products
keyword = house SELECT * FROM products WHERE description LIKE '%house%' This query also
If I use this statement: $query = select * from Products where category_description='.$search_dept.' ORDER
How would I do the following with CF ORM? SELECT * FROM products WHERE
select product.id,product.name,product.itemcode,sum(product.amount)as total_amount from product where product.account in select G.account from report_results G where
So I have a SQL Query as Follows SELECT P.Date, P.CategoryName, P.ProductName, SUM(Quantity) Quantity,

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.