I've got a problem and it's making my head spin. I think there is a very simple solution to this but I can't figure it out.
SELECT ck.id, ck.position AS position,ads.id,ads.bid_type,ads.bid_amount,sort_col FROM v.content_keyword ck
STRAIGHT_JOIN vc.campaign_ad ads ON ads.keyword_id=ck.keyword_id
WHERE ck.content_id=27438 ORDER BY ck.position,sort_col DESC
This produces:
id pos ad_id type bid sort_col
40 188 1113596 PPV 15 1015
40 188 1143404 PPV 11 1011
18 192 890250 PPV 13 1013
18 192 895096 PPV 13 1013
18 192 977947 PPV 10 1010
8 205 860333 PPV 39.22 1039.22
8 205 739434 PPV 11 1011
48 265 1137777 PPV 35.01 1035.01
48 265 689505 PPV 13 1013
But I am only interested in the first set of results unique to each id, so the first (40), the first (18), the first (8) and the first (48) result (including all the columns).
I tried GROUP BY ck.id but that seems to group the first ad based on ID and not based on the bid amount (the sorted column). MAX(), etc also only pick the max value, but don't tie it do the ad_id or any of the other things.
Any ideas?
Thanks!
SELECT ck.id, ck.position AS position,ads.id,ads.bid_type,ads.bid_amount,sort_col FROM v.content_keyword ck
STRAIGHT_JOIN vc.campaign_ad ads ON ads.keyword_id=ck.keyword_id
WHERE ck.content_id=27438 ORDER BY ck.position,sort_col DESC
This produces:
id pos ad_id type bid sort_col
40 188 1113596 PPV 15 1015
40 188 1143404 PPV 11 1011
18 192 890250 PPV 13 1013
18 192 895096 PPV 13 1013
18 192 977947 PPV 10 1010
8 205 860333 PPV 39.22 1039.22
8 205 739434 PPV 11 1011
48 265 1137777 PPV 35.01 1035.01
48 265 689505 PPV 13 1013
But I am only interested in the first set of results unique to each id, so the first (40), the first (18), the first (8) and the first (48) result (including all the columns).
I tried GROUP BY ck.id but that seems to group the first ad based on ID and not based on the bid amount (the sorted column). MAX(), etc also only pick the max value, but don't tie it do the ad_id or any of the other things.
Any ideas?
Thanks!