Thread:

From
"postgresql"
Date:
I am basically self taught with sql. I find that I keep re-reading the 
postgresql tutorials tryin to add a little more to my understanding. 

so my question is... Is this the best way to word this querry?
I have two tables, fc_client_info and fc_communication. I keep reading 
the section on JOINs and wonder if I should querry this differently. for 
some reason I have been shying away from JOINs (I haven't figures them 
out).

SELECT i.cname FROM fc_client_info i, fc_communication c WHERE i.acode = 
c.acode AND c.contactdate = '09/06/2001' ORDER BY lower(cname);

Thank for your great software.... I am really beginning to like SQL... 

Ted




Re:

From
Haller Christoph
Date:
My understanding is you did it the best way. 
Alternatively, you may word your query as 
SELECT i.cname FROM fc_client_info i 
WHERE EXISTS ( SELECT * FROM fc_communication c               WHERE c.acode = i.acode        AND c.contactdate =
'09/06/2001')
 
ORDER BY lower(i.cname);
instead of 
SELECT i.cname FROM fc_client_info i, fc_communication c WHERE i.acode =
c.acode AND c.contactdate = '09/06/2001' ORDER BY lower(cname);

I suppose the correlated subquery using the EXISTS predicate, which 
results in an outer loop join, is much slower than your originally 
used sort-merge join. 
Try, but make sure both tables are well populated, otherwise the 
benchmark result is no good. 
Christoph 


Re:

From
"postgresql"
Date:
I had a suspicion that JOIN was going to be part of the answer. I 
guess I had not found documentation that really helped. I have been 
searching for more information.

I found this:
11.2. Controlling the Planner with Explicit JOINs

I guess I am just slow.... It mentions 'inner joins', outer joins, left 
joins. .... I get lost. Where can I get more info. I really want  to 
understand.

Thanks for your time. I guess it's back to the bookstore.


-----Original Message-----
From: "Joseph Syjuco" <joseph@asti.dost.gov.ph>
To: "postgresql" <pgsql@symcom.com>
Date: Fri, 7 Sep 2001 08:50:20 +0800
Subject: RE: [SQL]

> select i.cname from fc_client_info i inner join fc_communication c 
on i.acode=c.acode where c.contactdate='090601' order by cname
> 
> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org
> [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of postgresql
> Sent: Friday, September 07, 2001 1:12 AM
> To: PgSQL-SQL
> Subject: [SQL]
> 
> 
> I am basically self taught with sql. I find that I keep re-reading the
> postgresql tutorials tryin to add a little more to my understanding.
> 
> so my question is... Is this the best way to word this querry?
> I have two tables, fc_client_info and fc_communication. I keep 
reading
> the section on JOINs and wonder if I should querry this differently.
> for
> some reason I have been shying away from JOINs (I haven't 
figures them
> out).
> 
> SELECT i.cname FROM fc_client_info i, fc_communication c 
WHERE i.acode
> =
> c.acode AND c.contactdate = '09/06/2001' ORDER BY 
lower(cname);
> 
> Thank for your great software.... I am really beginning to like SQL...
> 
> Ted