I’m trying to filter a query by a subtable column’s value… Is that possible?
for example,
I’m trying to get orders that include products with quantity > 10)
Orders: 1. Order 1 has 2 products,
product A, has 5 pieces X 10€
product B, has 15 pieces X 10€
2. Order 2 has 2 products,
product A, has 25 pieces X 10€
product B, has 12 pieces X 10€
3. Order 3 has 3 products,
product A, has 15 pieces X 10€
product B, has 22 pieces X 10€
product C, has 17 pieces X 10€
The result of my query should output only 2 resuls: Order 2 and Order 3
(Order 1 should not match the condition because has 1 product with quantity 5 pcs)
I think I found a way to work on this without Custom Query but I get an error…
Before my Main query, I added a query based on my subtable, pulling the Order_ID ONLY when the product_Category_ID exists in the categories_ID Array (GET_catid).
The query will return an error, just like any other condition where not a valid value is passed. And empty string will generate a query like SELECT * FROM table WHERE col IN () which is invalid. That is why we have conditional conditions where you specify when it should be applied.
We could assume that when the array is empty you probably didn’t want to filter on it, but does that mean you wanted it to return all records or none? This is not only for IN, but also for other conditions. When you have SELECT * FROM table WHERE id = ? and the value for the id is not set, should we then assume 0 and return nothing or did you mean to return them all?