如何在两列中获取两行的结果 我的疑问是 -
select tt.* from wp_terms AS tt where tt.terms_id='" . $establishment['term_id'] . "' AND tt.meta_key ='phone';
select tt.* from wp_terms AS tt where tt.terms_id='" . $establishment['term_id'] . "' AND tt.meta_key ='location';
每个查询给我结果
meta_id terms_id meta_key meta_value
6926 16 phone 0000
meta_id terms_id meta_key meta_value
6927 16 location xxx
现在我希望结果为
meta_id terms_id meta_value meta_value1
6926 16 0000 xxx
请帮忙 谢谢
答案 0 :(得分:0)
SELECT t.meta_id, t.terms_id, t.meta_value, tt.metaValue AS meta_value1
FROM wp_terms AS t
INNER JOIN wp_terms AS tt ON t.terms_id = tt.terms_id
AND t.meta_key = 'phone'
AND tt.meta_key = 'location'
WHERE t.terms_id='" . $establishment['term_id'] . "'
答案 1 :(得分:0)
也许是这样的。
select phone.meta_id, phone.terms_id, phone.meta_value as phone, location.meta_value as location
from
(select tt.* from wp_terms AS tt where tt.terms_id='" . $establishment['term_id'] . "' AND tt.meta_key ='phone') phone,
(select tt.* from wp_terms AS tt where tt.terms_id='" . $establishment['term_id'] . "' AND tt.meta_key ='location') location
where phone.meta_id = location.meta_id