All pastes #394320 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-14 06:10 UTC
rendered paste body
3.6.4. The Rows Holding the Group-wise Maximum of a Certain Field
Task: For each article, find the dealer or dealers with the most expensive price. 

This problem can be solved with a subquery like this one: 

SELECT article, dealer, price
FROM   shop s1
WHERE  price=(SELECT MAX(s2.price)
              FROM shop s2
              WHERE s1.article = s2.article);