Need a MySQL query to fetch product if provided range of price falls between the min and max price.
I have product A and product B. Product A has a min price equal to 3400 and max price equal to 5000 and Product B has a min price equal to 4400 and max price equal to 7000, stored in postmeta table (WordPress). Now I need a mysql query that should work with all below cases (not at a same time)
- When a user sets a filter with min price equal to 3800 and leave max price filter empty then product A must be fetched as this price range comes in between 3400 and 5000
- When a user sets a filter with max price equal to 5000 and leave min price filter empty then both product A and product B must be fetched as 5000 comes in between 3400 and 5000 which is product A price and also in between 4400 and 7000 which is product B price.
- When a user sets min price filter to 4500 and max price filter to 6000 then both products must be fetched as the max and min filter prices comes in between the min and max price of the product.
2
Answers
you can use the following query: