Received: from tomts8-srv.bellnexxia.net (tomts8.bellnexxia.net [209.226.175.52]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g07M98B99509 for ; Mon, 7 Jan 2002 17:09:08 -0500 (EST) (envelope-from fbax@sympatico.ca) Received: from ACER ([65.93.5.240]) by tomts8-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with SMTP id <20020107220909.SSPT16860.tomts8-srv.bellnexxia.net@ACER> for ; Mon, 7 Jan 2002 17:09:09 -0500 Message-Id: <3.0.6.32.20020107170828.0099e8b0@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) Date: Mon, 07 Jan 2002 17:08:28 -0500 To: From: Frank Bax Subject: Re: simple? join In-Reply-To: References: <3.0.6.32.20020104121000.00996cb0@pop6.sympatico.ca> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200201/42 X-Sequence-Number: 6133 At 12:22 AM 1/6/02 -0500, Peter Eisentraut wrote: >Frank Bax writes: >> EMPLOYEE table contains: emp, first, last (emp is unique key) >> TIMESHEET table contains: emp, timestamp, hours >> I want to report employee name and total hours. >> SELECT first, last, sum(ts.hours) >> FROM timesheet ts, employee emp >> WHERE ts.emp = emp.emp >> GROUP by emp.emp, first, last >> ORDER BY last, first; >> >> It seems silly to specify extraneous "group by" fields. > >There's nothing "extraneous" there. Both first and last could be >duplicated, so you need to group by each one. But first and last can't be duplicated if emp is defined as unique. If I am also selecting a dozen or so other fields from "employee" table, must I also include them all in the GROUP BY clause, even though I know "emp" identifies a unique row in this table? Frank