O
O
on_click2020-02-27 16:15:02
SQL
on_click, 2020-02-27 16:15:02

Is it possible to combine these 2 sql queries?

Good afternoon
Tell me please, is it possible to combine these two requests into 1?

First, gets the id of all records of the term I need

IDS_ARRAY = 

SELECT id FROM wp_posts
LEFT JOIN wp_term_relationships ON
(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy ON
(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE wp_posts.post_type = 'water'
AND wp_term_taxonomy.taxonomy = 'menu'
AND wp_term_taxonomy.term_id = 22
ORDER BY post_date DESC


The second one gets the custom fields I need from those records that were found above (IDS_ARRAY)
SELECT * FROM wp_postmeta WHERE post_id in (IDS_ARRAY) AND meta_value LIKE "field\_%" AND meta_key LIKE "%sku%"


In total, respectively, we need data from the second request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-27
@on_click

https://www.dofactory.com/sql/subquery

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question