I am making a sql query to show me the following:
1.- Results that have "_go_product_url" in the meta_key and that is not null.
2.- And I need it to only show me in the results based on the first query that do not have the meta_key "_go_product_info"
What would be the best method without spending a lot of resources on the server?
I am working with wordpress. But for now testing in phpmyadmin
I did this query but without results
SELECT * FROM `wp_postmeta`
WHERE `meta_key` LIKE '%_go_product_url%' AND `meta_value` IS NOT NULL AND NOT EXISTS (SELECT * FROM `wp_postmeta` WHERE `meta_key` LIKE '%_go_product_info%' IS NULL);
>Solution :
You presumably want to identify posts meeting these criteria, so you should be selecting something like the post_id
and/or the other columns you want. Here is one aggregation approach:
SELECT post_id
FROM wp_postmeta
GROUP BY post_id
HAVING SUM(meta_key LIKE '%_go_product_url%') > 0 AND
SUM(meta_key LIKE '%_go_product_info%') = 0;