From: Tom Lane <tgl@sss.pgh.pa.us>
To: SCAHILL KEVIN <9726209@student.ul.ie>
Cc: 'pgsql-sql@postgreSQL.org' <pgsql-sql@postgresql.org>
Subject: Re: SELECT DISTINCT problems
Date: Wed, 28 Feb 2001 10:35:00 -0500
Message-ID: <18169.983374500@sss.pgh.pa.us> (raw)
In-Reply-To: <992C0C12C388D411B264009027AA341804258E7F@gabriel.ul.ie>
References: <992C0C12C388D411B264009027AA341804258E7F@gabriel.ul.ie>
SCAHILL KEVIN <9726209@student.ul.ie> writes:
> I have tried this but it does not work:
> Set rsLecturers = Server.CreateObject("ADODB.Recordset")
> sqlLect = "Select LecturerName, MIN(ProjectCode) from tblSuggestions WHERE
> LecturerName IN ( SELECT DISTINCT LecturerName FROM tblSuggestions)"
> rsLecturers.Open sqlLect, Conn, 3, 3
You seem to be trying to re-invent the notion of GROUP BY. The correct
way to write this sort of query in SQL is
Select LecturerName, MIN(ProjectCode) from tblSuggestions GROUP BY LecturerName
This gives you one output row for each distinct value of LecturerName,
and within that row the MIN() aggregates over all the original rows that
have that LecturerName. See
http://www.postgresql.org/devel-corner/docs/postgres/query-agg.htmlhttp://www.postgresql.org/devel-corner/docs/postgres/queries.html#QUERIES-GROUP
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, 9726209@student.ul.ie
Subject: Re: SELECT DISTINCT problems
In-Reply-To: <18169.983374500@sss.pgh.pa.us>
References: <992C0C12C388D411B264009027AA341804258E7F@gabriel.ul.ie> <18169.983374500@sss.pgh.pa.us>
* 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