Mysql join gives duplicate rows

Deepak picture Deepak · Jun 15, 2011 · Viewed 37.8k times · Source

I have 2 tables and i am using join to get common records from those 2 tables. i have used the following query but my problem is i am getting the records doubled. The query is as follows

SELECT * FROM pos_metrics pm INNER JOIN pos_product_selling pps ON   
pm.p_id=pps.p_id WHERE pm.p_id='0' AND pps.pos_buying_id='0' AND pm.type=1

pos_metrics table:
enter image description here

pos_product_selling table: enter image description here

Output:

enter image description here

EDIT
When I tried to use GROUP BY and DISTINCT together I am not getting duplicates but the value from the second table is repeated. Any other solutions ?

Answer

Jayakrishnan K picture Jayakrishnan K · Nov 12, 2015

Try something like these

GROUP BY pos_product_selling.metrics