Deleting rows from table where values less than an aggregate value
You can select the rows to keep using a left join - http://sqlfiddle.com/#!9/3a677/3

select *
from media_views m1
left join media_views m2
  on (m1.companyid = m2.companyid
      and m1.channel = m2.channel
      and m1.date = m2.date
      and m1.views &lt; m2.views)
where m2.companyid is null;


And you can delete the other ones using similar a inner join - http://sqlfiddle.com/#!9/d5d36/2

delete m1 from media_views m1
join media_views m2
  on (m1.companyid = m2.companyid
      and m1.channel = m2.channel
      and m1.date = m2.date
      and m1.views &lt; m2.views);


And do not forget to modify the primary key after deleting them so it is not possible anymore.