Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6FE33632BB0 for ; Fri, 9 Oct 2009 20:00:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70871-02 for ; Fri, 9 Oct 2009 23:00:38 +0000 (UTC) X-Greylist: delayed 00:06:47.548887 by SQLgrey-1.7.6 Received: from tim.des.no (tim.des.no [194.63.250.121]) by mail.postgresql.org (Postfix) with ESMTP id 7E6F9633F7C for ; Fri, 9 Oct 2009 20:00:38 -0300 (ADT) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 0420E6D41B for ; Fri, 9 Oct 2009 22:53:47 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 9E3F3844DA; Sat, 10 Oct 2009 00:53:47 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: pgsql-sql@postgresql.org Subject: Existential quantifier Date: Sat, 10 Oct 2009 00:53:47 +0200 Message-ID: <86bpkgqiv8.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.74 tagged_above=-10 required=5 tests=BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 200910/34 X-Sequence-Number: 33233 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Consider the attached schema (filmstars.sql), which is a poorly designed database of films and actors. The following query gives me a list of films in which either Charlie or Martin Sheen starred: select fs.film.title, fs.film.year from fs.film left join fs.star on fs.film.id =3D fs.star.film where fs.star.last =3D 'Sheen' group by fs.film.title, fs.film.year; Is there a way to do this without the "group by" clause? DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no --=-=-= Content-Disposition: inline; filename=filmstars.sql drop schema fs cascade; create schema fs; create table fs.film ( id serial not null primary key, title varchar not null unique, year integer not null ); create table fs.star ( id serial not null primary key, film integer not null references fs.film(id), last varchar not null, first varchar not null, unique (film, last, first) ); insert into fs.film(title, year) values ('Apocalypse Now', 1979); insert into fs.star(film, last, first) select id, 'Sheen', 'Martin' from fs.film where title = 'Apocalypse Now'; insert into fs.star(film, last, first) select id, 'Brando', 'Marlon' from fs.film where title = 'Apocalypse Now'; insert into fs.star(film, last, first) select id, 'Duvall', 'Robert' from fs.film where title = 'Apocalypse Now'; insert into fs.star(film, last, first) select id, 'Ford', 'Harrison' from fs.film where title = 'Apocalypse Now'; insert into fs.film(title, year) values ('Blade Runner', 1982); insert into fs.star(film, last, first) select id, 'Ford', 'Harrison' from fs.film where title = 'Blade Runner'; insert into fs.star(film, last, first) select id, 'Young', 'Sean' from fs.film where title = 'Blade Runner'; insert into fs.star(film, last, first) select id, 'Hauer', 'Rutger' from fs.film where title = 'Blade Runner'; insert into fs.star(film, last, first) select id, 'Hannah', 'Daryl' from fs.film where title = 'Blade Runner'; insert into fs.film(title, year) values ('Platoon', 1986); insert into fs.star(film, last, first) select id, 'Sheen', 'Charlie' from fs.film where title = 'Platoon'; insert into fs.star(film, last, first) select id, 'Dafoe', 'Willem' from fs.film where title = 'Platoon'; insert into fs.star(film, last, first) select id, 'Berenger', 'Tom' from fs.film where title = 'Platoon'; insert into fs.film(title, year) values ('Wall Street', 1987); insert into fs.star(film, last, first) select id, 'Douglas', 'Michael' from fs.film where title = 'Wall Street'; insert into fs.star(film, last, first) select id, 'Sheen', 'Charlie' from fs.film where title = 'Wall Street'; insert into fs.star(film, last, first) select id, 'Hannah', 'Daryl' from fs.film where title = 'Wall Street'; insert into fs.star(film, last, first) select id, 'Sheen', 'Martin' from fs.film where title = 'Wall Street'; --=-=-=--