4

I have a table wp_postmeta with columns called meta_key and meta_value. I have 5 records in meta_key (location,area,price,bedrooms,bathrooms)

screenshot of table here

For example, I want to find a hotel in Texas with 2 bathrooms:

select post_id from wp_postmeta where meta_key = 'location' and meta_value = 'texas' and where meta_key = 'bathrooms' and meta_value= '2';

I know the above SQL command is not valid. Can anyone please help me to achieve the above result?

1 Answer 1

4

You can try mysql subquery:

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')
Sign up to request clarification or add additional context in comments.

1 Comment

awesome its working... but i did small correction it should be 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'), rest works like charm, thanks alot :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.