具有多个where子句的M​​ySQL查询

时间:2012-08-12 06:57:13

标签: mysql

我的表格 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命令无效。谁能帮助我实现上述结果?

1 个答案:

答案 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')