Answer the question
In order to leave comments, you need to log in
How to search by end part of a key in sql?
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 Северный
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` LIKE `fromdistrict_%`
AND c.`value` = 'Садовое кольцо'
)
Answer the question
In order to leave comments, you need to log in
there is a word like:
select * from mytable where myfield like '%SOMETHING' -- ищет чтоб SOMETHING было в конце
select * from mytable where myfield like '%SOMETHING%' -- ищет в нутри с любой позиции
select * from mytable where myfield like 'SOMETHING%' -- ищет сначала.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question