元表

时间:2015-09-22 13:33:03

标签: mysql sql search select metadata

我有一个如下所示的表格结构

enter image description here

我正在运行搜索查询,搜索提供的属性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' 

1 个答案:

答案 0 :(得分:0)

要获得分别有meta_name pricepropertyvalue以及meta_value 100010000的所有内容,您需要这样做。< / 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'

中选择