There is a table (wp_postmeta), the structure is as follows:
id post_id key value 1 11 fromcity_1 Москва 2 11 fromdistrict_1 Садовое кольцо 3 11 fromcity_2 Воронеж 4 11 fromdistrict_1 Коминтерновский 5 13 fromcity_2 Воронеж 6 13 fromdistrict_1 Северный And there is such a request:
SELECT `post_id` FROM `wp_postmeta` AS p WHERE p.`key` LIKE 'fromcity_%' AND p.`value` = 'Москва' AND EXISTS ( SELECT 1 FROM wp_postmeta AS c WHERE c.post_id = p.post_id AND c.`key` = concat('fromdistrict_', substring(p.`key`, 9)) AND c.`value` = 'Садовое кольцо' ) In theory, it should return post_id , where fromcity_1 = Вороклини , and fromdistrict_1 = Центр , but not working.
At the same time, the number 1 in keys is ID , and in keys fromcity_ and fromdistrict_ ID must match, which I do here:
AND c.`key` = concat('fromdistrict_', substring(p.`key`, 9)) But, apparently, I somehow incorrectly use the substring, since it does not work ...
key, 9)) p.key= fromcity_1. So in thesubstring(p.Key, 9))only the number 1 should remain. - RattleSneyk