0

I have a query that gets a sku_product product that is sold on a precise date

SELECT stock_products.`related_warehouse_position_id`, `product_code`, `EAN_CODE`, `custom_cart_picked_up`, `warehouse`, sum(`RemainingStock`), stock_products.`time_Picked_up` 
FROM `product_warehouse_position` 
INNER JOIN stock_products ON product_warehouse_position.id = stock_products.related_warehouse_position_id 
WHERE stock_products.time_Picked_up < '2017-10-10' 
GROUP BY product_code 
HAVING SUM(RemainingStock) = 0

Now i've tried with this query but the result is wrong.

I've try to make a subquery, but i need to get a time_pickedUp which is located on stock_products table.

SELECT `id` ,`product_code`, `EAN_CODE`, `custom_cart_picked_up`, `warehouse`, sum(`RemainingStock`) 
FROM product_warehouse_position 
WHERE product_code IN (
    SELECT product_stock_sku, time_Picked_up 
    FROM `stock_products` 
    WHERE stock_products.time_Picked_up < '2017-05-01'
) 
GROUP BY product_warehouse_position.product_code 
HAVING SUM(product_warehouse_position.`RemainingStock`) = 0 

This query return an error :

Operand should contain 1 column(s).

How to solve this problem without change the structure of this query?

Community
  • 1
  • 1

1 Answers1

0

If your query is correct then the only thing you need to do is remove the column time_Picked_up from the select in your inner query. You can still filter on that column in your WHERE clause.

isaace
  • 3,336
  • 1
  • 9
  • 22