Custom Select Query for meta table

妖精的绣舞 提交于 2019-12-25 17:51:11

问题


I have a table structure as shown below

I am running a query for search that searches for property id with provided meta_value against meta_name.

I have used union, self join, union all methods but were not working, please suggest me query that will get a data

mysql queries are

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:


to get all that have meta_name price and propertyvalue and meta_value 1000 and 10000 respectively, you need to do this.

SELECT * FROM `table` WHERE (meta_name = 'price' and meta_value = '1000') OR (meta_name = 'propertyvalue' and meta_value = '10000')

this will select both from table where meta_name = 'price' and meta_value = '1000' and meta_name = 'propertyvalue' and meta_value = '10000'



来源:https://stackoverflow.com/questions/32718318/custom-select-query-for-meta-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!