From: Frank Bax <fbax@sympatico.ca>
To: pgsql-sql@postgresql.org
Subject: simple? join
Date: Fri, 04 Jan 2002 12:10:00 -0500
Message-ID: <3.0.6.32.20020104121000.00996cb0@pop6.sympatico.ca> (raw)
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.
So far, I've come up with:
SELECT min(emp.first) as first, min(emp.last) as last, sum(ts.hours)
FROM timesheet ts, employee emp
WHERE ts.emp = emp.emp
GROUP by emp.emp
ORDER BY last, first;
It seems silly to specify "min" when I know there is only one value per emp!
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.
Is there a 'better' way to write this SQL?
Frank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: fbax@sympatico.ca
Subject: Re: simple? join
In-Reply-To: <3.0.6.32.20020104121000.00996cb0@pop6.sympatico.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox