Re: [SQL] Subquery problems

From: Dimitri <dimitri(at)France(dot)Sun(dot)COM>
To: Jerome Knobl <jknobl(at)mandanet(dot)ch>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Subquery problems
Date: 1998-08-12 12:59:02
Message-ID: 98081215132106.00535@dimitri
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 12 Aug 1998, you wrote:
>Hello,
>
>I'm trying to build some subquery, and it don't works like I want.
>
>I try the following query :
>
>select distinct pseudo, (select count(ref) from questions where
>questions.refpseudo=pseudos.refold) as xxx from pseudos;

You have to try:

select pseudo, count(ref) as xxx
from pseudos, questions
where questions.refpseudo=pseudos.refold
group by pseudo;

or

select pseudo, count(*) as xxx
from pseudos, questions
where questions.refpseudo=pseudos.refold
group by pseudo;

This'll be more correct on SQL point and will be more faster
to execute because you will avoid duplication in your output...

>
>That query work well on MSAccess, but I have the following error on
??? M$ SQL is not a good reference... :))

>postgres :
>
>ERROR: parser: parse error at or near "select"
>
>I must maybe using an other method. I'm want to optain in a simple query
>to list some name of my table pseudos and to see the number of occurency
>in the table questions.
>
>Thank. Jrme Knbl, Switzerland

Hope it helps,
(dim)

--
=====================================================
Dimitri KRAVTCHUK (dim) Sun Microsystems
Benchmark Engineer France
dimitri(at)France(dot)Sun(dot)COM
=====================================================

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Walt Bigelow 1998-08-12 18:31:38 returning the current date in a SQL query
Previous Message Holger Mitterwald 1998-08-12 12:50:02 Re: [SQL] Query based on date/time field