I have following data in my tables
-------------------------------------------------------------------------- | S.No | name | quantity | price | sold_by | -------------------------------------------------------------------------- |bk005 | Book 1 | 4 | 120 | XYZ | -------------------------------------------------------------------------- |bk007 | Book 2 | 2 | 60 | XYZ | -------------------------------------------------------------------------- |bk009 | Book 2 | 2 | 60 | ME | -------------------------------------------------------------------------- |bk011 | Book 1 | 4 | 100 | ME | --------------------------------------------------------------------------
I am using GROUP BY clause get a unique book. But if price of a book I am selling is lesser than of other competitors then book with sold_by ME must be selected else any random row can be selected. Is there a way to achieve this?