SELECT product.product_id, product.product_brand_id, product.product_model_id, product.product_subcategory_id, product.product_retail_price, product.product_wholesale_price, SUM(product_sold.product_quantity) AS product_quantity_sold, SUM(product_sold.product_total_price) AS total_price_sold FROM product LEFT JOIN product_sold ON product.product_id = product_sold.product_id LEFT JOIN sales ON sales.sales_id = product_sold.product_sales_id WHERE sales.sales_approved = '1' AND sales.sales_approved_time > '$start_timestamp' AND sales.sales_approved_time < '$end_timestamp' GROUP BY product.product_id ORDER BY SUM(product_sold.product_quantity) DESC
What I want is to display products even if they havent been sold, I originally had INNER JOIN then I changed it to LEFT JOIN thinking that it will display all the product from PRODUCT table and order them by the quantity sold and display non sold products at the end. Well I hope I can get some help I been doing this query in different ways but havent come close to what I want, Thanks in advanced. Bryan

New Topic/Question
Reply



MultiQuote



|