我的表格 wp_postmeta 包含名为 meta_key 和 meta_value 的列。我在 meta_key (地点,区域,价格,卧室,浴室)中有5条记录
screenshot of table here http://img716.imageshack.us/img716/4979/tablegh.jpg
例如,我想在德克萨斯州找到一间带2间浴室的酒店:
select post_id from wp_postmeta where meta_key = 'location' and meta_value = 'texas' and where meta_key = 'bathrooms' and meta_value= '2';
我知道上面的SQL命令无效。谁能帮助我实现上述结果?
答案 0 :(得分:3)
您可以尝试使用mysql子查询:
select post_id
from wp_postmeta
where meta_key = 'location' and meta_value = 'texas'
and post_id IN (select post_id
from wp_postmeta
where meta_key = 'bathrooms' and meta_value= '2')