List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:March 12 1999 9:38pm
Subject:Re: SQL question
View as plain text  
On Fr, 1999-03-12 16:54:42 +0100, Harry Brückner wrote:
> Now I want to select each article just once, where it has the amount
> is the maximum.

What you need is "GROUP BY", because you group all rows with the same
Shop and Articles together and then sum up the Amount inside each group:

  SELECT Shop, Article, sum(Amount)
  FROM shop
  GROUP BY Shop, Article;

> 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 ?

The only (quote good) one I know about is:

  SQL Tutorial by James Hoffman
  <URL: http://www.geocities.com/ResearchTriangle/Node/9672/sqltut.html >

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
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