问题
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