I have a table aus_woocommerce_order_itemmeta with the following schema:
How can I create a query that yields the following logic?
SELECT * FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
/* And only from those items, the ones with order_item_id = 660
SELECT the rows that meet any of the following conditions: */
meta_key LIKE "%bebida caliente%"
meta_key LIKE "%elige%"
meta_key LIKE "%agregar%";
This is my current query:
SELECT order_item_id, meta_key, meta_value
FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
AND meta_key LIKE "%bebida caliente%"
OR meta_key LIKE "%elige%"
OR meta_key LIKE "%agregar%";
But obviously, the OR statements are on the same level as the first WHERE condition, so it’s returning everything, regardless of its order_item_id.
>Solution :
Just wrap the or statement in a parenthesis like this.
SELECT order_item_id, meta_key, meta_value
FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
AND (meta_key LIKE "%bebida caliente%"
OR meta_key LIKE "%elige%"
OR meta_key LIKE "%agregar%");
