I have two tables in my database. Table Name: product_price_range Field Type ----------------------------- price_category_id int(11) title varchar(155) min_price float max_price float Data: product_price_range price_category_id title min_price max_price ----------------- ----------- --------- --------- 1 1-49 1 49 2 50-99 50 99 3 100-199 100 199 4 200-299 200 299 5 300-erboven 300 0 Second Table: product Field Type ----------------------------- product_id int(11) title varchar(155) price float Data: product product_id title price ---------- ----------- --------- 1 product1 49 2 product2 99 3 product3 149 4 product4 249 5 product5 300 Code (markup): Now I want to show the only those price range in which product price is available. For that I need a query or other possible way to identify those price range. In above example output should be 1. 1-49 2. 50-99 4. 200-299 Can anyone help me out in this issue? Regards, Amit Shah
You should add a category_id foreign key to the products table, then just do a left join and group it.
Ok, I resolved the issue. Find below query for same. SELECT DISTINCT ppr.title FROM product_price_range AS ppr INNER JOIN product AS p ON p.price BETWEEN ppr.min AND CASE WHEN ppr.max = 0 THEN 9999999999 ELSE ppr.max END Code (markup): Regards, Amit