From: Jussi Vainionpää <jjvainio@cc.hut.fi>
To: pgsql-sql@postgresql.org
Subject: Trouble with subqueries
Date: Fri, 19 Jan 2001 09:34:50 +0200
Message-ID: <3A67EE1A.B7319298@cc.hut.fi> (raw)
I have the following two tables:
create table movies (
name varchar(80),
info varchar(80),
length int,
primary key (name)
);
create table ratings (
name varchar(80),
userid varchar(10),
rating char(1),
foreign key (name) references movies,
primary key(name, userid)
);
The tables contain movies and users' ratings of the movies.
I would like to get a listing of all the movies along with how many
users have given the movie some particular rating. The first solution
that I came up with was this:
SELECT name, length, fives
FROM movies,
(SELECT name as rname,
count(*) as fives
FROM ratings
WHERE rating='5'
GROUP BY name)
WHERE name=rname;
but in PostgreSQL 7 it just gives me this error message:
ERROR: parser: parse error at or near "("
I have previously used similar queries in Oracle where they have worked,
so it would seem to me that PostgreSQL doesn't support subselects after
all despite all the claims.
Am I doing something wrong or/and is there some another way of making
this query that would work in PostgreSQL?
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: jjvainio@cc.hut.fi
Subject: Re: Trouble with subqueries
In-Reply-To: <3A67EE1A.B7319298@cc.hut.fi>
References: <3A67EE1A.B7319298@cc.hut.fi>
* 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