схема
CREATE TABLE custom (
meta_id INTEGER,
post_id INTEGER,
meta_key VARCHAR(32),
meta_value VARCHAR(32)
);
INSERT INTO
custom
VALUES
(6, 2, 'seo_descr', 'Описание стр 2');
INSERT INTO
custom
VALUES
(7, 2, 'seo_title', 'Заголовок стр 2');
INSERT INTO
custom
VALUES
(8, 1, 'seo_descr', 'Описание стр 1');
INSERT INTO
custom
VALUES
(9, 1, 'seo_title', 'Заголовок стр 1');
запрос
SELECT
DISTINCT t1.post_id AS id,
t2.meta_value AS seo_title,
t3.meta_value AS seo_descr
FROM
custom t1
LEFT JOIN custom t2 ON t1.post_id = t2.post_id
AND t2.meta_key = 'seo_title'
LEFT JOIN custom t3 ON t1.post_id = t3.post_id
AND t3.meta_key = 'seo_descr'
ORDER BY
t1.post_id;