From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Dag-Erling Smørgrav <des(at)des(dot)no> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Existential quantifier |
Date: | 2009-10-09 23:06:56 |
Message-ID: | 20091009160318.J80119@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Sat, 10 Oct 2009, [utf-8] Dag-Erling Smrgrav wrote:
> 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 = fs.star.film
> where fs.star.last = 'Sheen'
> group by fs.film.title, fs.film.year;
>
> Is there a way to do this without the "group by" clause?
Not at all tested as I don't have access to my db right now, but I think
something like one of these would work:
select fs.film.title, fs.film.year
from fs.film
where exists(select 1 from fs.star where fs.film.id = fs.star.film
and fs.star.last = 'Sheen');
select fs.film.title, fs.film.year
from fs.film
where fs.film.id in (select fs.star.film where fs.star.last = 'Sheen');
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Albright | 2009-10-09 23:11:09 | Re: Existential quantifier |
Previous Message | Dag-Erling Smørgrav | 2009-10-09 22:53:47 | Existential quantifier |