List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:March 12 1999 7:13pm
Subject:Re: SQL question
View as plain text  
Harry Brueckner wrote:
> 
> Hello,
> 
> I have problems getting the proper SQL statement for the following problem.
> 
> I have this table:
> 
> | Shop | Article | Amount |
> | A    |       1 |      3 |
> | B    |       1 |     17 |
> | C    |       1 |      9 |
> | D    |       1 |     25 |
> | A    |       2 |     14 |
> | B    |       2 |     29 |
> | G    |       2 |      1 |
> | D    |       3 |    212 |
> | E    |       3 |     17 |
> | F    |       3 |     35 |
> 
> Now I want to select each article just once, where it has the amount is the
> maximum.
> The result for my example should be:
> 
> | Shop | Article | Amount |
> | D    |       1 |     25 |
> | B    |       2 |     29 |
> | D    |       3 |    212 |
> 
> How can I select just these rows ?
> 
> Harry
> 
> PS: Does anyone know a good SQL book which helps to get those little harder
>     SQL questions answered. Something like a "SQL Cookbook" or something ?

Hi Harry

Try:
SELECT Shop, Article, Amount FROM table HAVING Amount = MAX( Amount )

Books:
'SQL for Dummies' is good to get an first insight.

Tschau
Christian

Thread
SQL questionHarry Brueckner12 Mar
  • Re: SQL questionMartin Ramsch13 Mar
  • Re: SQL questionChristian Mack13 Mar
  • Re: Mysql update logs trouble.sinisa20 Apr
  • Re: Innobase released in MySQL-3.23.34a source distribution: transactions and row level locking now in MySQLJean-Luc Fontaine12 Mar