Question

Im trying to get a list of products order by the amount sold and by date... I also want to display the products that havent been sold in the list so I tried doing a subquery but MYSQL is giving me this message:

Operand should contain 1 column(s)

This is the query im using:

SELECT product.product_id, product.product_brand_id, product.product_model_id, product.product_subcategory_id, product.product_retail_price, product.product_wholesale_price
FROM product
WHERE product.product_subcategory_id = $subcategory_id 
AND (SELECT SUM(product_sold.product_quantity) AS product_quantity_sold, SUM(product_sold.product_total_price) AS total_price_sold 
 FROM product
 INNER JOIN product_sold 
  ON product.product_id = product_sold.product_id
 INNER 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')
Was it helpful?

Solution

The AND operator expects a single value on either side, but you have this:

WHERE product.product_subcategory_id = $subcategory_id 
AND ( ... select that returns two columns)

The first operand is of the form X = Y, so that's a Boolean that evaluates as true or false (or NULL if the field is NULL), but the second operand isn't a Boolean.

To get this to work, you'll need to make the second operand of AND into a single-valued expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top