RE: [GENERAL] Subselect question

From: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
To: gfloridia(at)provider(dot)com(dot)br, pgsql-general(at)postgreSQL(dot)org
Subject: RE: [GENERAL] Subselect question
Date: 1999-01-04 23:23:05
Message-ID: F10BB1FAF801D111829B0060971D839F5B06C4@cpsmail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi,
>
> I have some trouble with subselects. (Version 6.3).
>
> If I try
>
> Select name, address from costumers where cod_costumer in (
> Select cod_costumer from logins where total_usage > 0);
>
> It take lots of time (really I din't wait till the end).
>
> But if I manualy split in
> Select cod_costumer from logins where total_usage > 0;
> getting
> ( 1, 9, 15, 18 , 40)
> and then use
> Select name, address from costumers where cod_costumer in ( 1, 9,
> 15, 18 , 40);
>
> All is OK.
>
> Is this type of subselect suported ?
>
> Thanks
> Giovanni Floridia
>

Yes it's supported, but the subselect will be executed for each row of
the main select.
This should be a faster select (but not as fast as your second one).
Select name, address from costumers where EXISTS(Select 1 from logins
where total_usage > 0 AND logins.cod_customer = customers.cod_customer);
-DEJ

Browse pgsql-general by date

  From Date Subject
Next Message Clark Evans 1999-01-05 00:49:56 Re: [GENERAL] 88, CREATE FUNCTION ON TABLE
Previous Message Anand Surelia 1999-01-04 21:21:25 Regress test failing on Sparc Solaris 2.5.1