jack brone jack brone - 1 year ago 66
MySQL Question

How to get unique rows based on one column using joins in mysql

Here I am trying to fetch products along with prices but here one condition is there that is title should be unique in results.

example: Nokia lumia 730 has three rows but I need to fetch only one row by giving price range in that category.

Please look here for schema


Answer Source

You can use : GROUP BY .

Ex :

 SELECT DISTINCT p.* from products AS p LEFT JOIN price AS p1 on p1.product_id=p.id WHERE p1.price >= '2000' AND p1.price <= '10000' AND p.category IN (6) GROUP BY title;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download