T have the following table:
mid pid price
1 100 10
1 200 10
1 300 10
1 400 10
2 500 20
2 600 30
2 700 20
3 800 40
3 900 50
I want to find the least priced pid for each mid.
for that I was querying this code.
SELECT t1.mid,t1.pid
FROM tableName t1
JOIN (
SELECT mid, min(price) as min_price
FROM tableName
GROUP BY mid
) as t2 on t1.mid = t2.mid and t1.price = t2.min_price;
Ideally it should give result, but in my case in each group there are multiple pid
having same price. so it is printing all the result.
but I just want to limit 1 row for each mid.
Is there any way to do this? I have a sqlfiddle demo