我有一个如下所示的表格结构
我正在运行搜索查询,搜索提供的属性ID meta_value对meta_name。
我使用了union,self join,union所有方法但没有工作,请建议我查询以获取数据
mysql查询
1)
SELECT property_id from
real_new_properties
where (meta_name = 'price' and meta_value = '1000')
and (meta_name = 'propertyvalue' and meta_value = '10000')
2)
SELECT property_id
from real_new_properties
where meta_name = 'price'
and meta_value = '1000'
UNION
SELECT property_id
from real_new_properties
where meta_name = 'propertyvalue'
and meta_value = '10000'
3)
SELECT property_id
from real_new_properties
where meta_name = 'price'
and meta_value = '1000'
UNION ALL
SELECT property_id
from real_new_properties
where meta_name = 'propertyvalue'
and meta_value = '10000'
答案 0 :(得分:0)
要获得分别有meta_name
price
和propertyvalue
以及meta_value
1000
和10000
的所有内容,您需要这样做。< / p>
SELECT * FROM `table` WHERE (meta_name = 'price' and meta_value = '1000') OR (meta_name = 'propertyvalue' and meta_value = '10000')
这将从table
meta_name = 'price' and meta_value = '1000'
和meta_name = 'propertyvalue' and meta_value = '10000'