Re: making queries more effecient

From: "Chad Thompson" <chad(at)weblinkservices(dot)com>
To: "Peter T(dot) Brown" <peter(at)memeticsystems(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: making queries more effecient
Date: 2002-11-01 22:04:42
Message-ID: 033301c281f2$aed1f7e0$32021aac@chad
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This should be all you need.

insert into VisitorPointer839 ("VisitorID")
select VisitorID
from ProgramEvent
Where ProgramID = 10
and Type = 0
group by VisitorID

You dont need order by because its not important the order it goes in the
database, just the order that it comes out.
I have found that group by works faster than distinct in some cases. You
may have to test it for your senario.

Thanks
Chad

----- Original Message -----
From: "Peter T. Brown" <peter(at)memeticsystems(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Friday, November 01, 2002 3:24 PM
Subject: [SQL] making queries more effecient

> Hi. I have this query that I have been trying to reduce to a single
> statement, but haven't figured out how. Am I missing something?
>
> CREATE TEMP TABLE temp20561149207391 AS SELECT DISTINCT ON ("VisitorID")
> "VisitorID","Type" FROM "ProgramEvent" WHERE "ProgramID" = 10 ORDER BY
> "VisitorID","Created" DESC;INSERT INTO "VisitorPointer839" ("VisitorID")
> SELECT temp20561149207391."VisitorID" FROM temp20561149207391 WHERE
> temp20561149207391."Type" = 0
>
>
> Thanks
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kevin Old 2002-11-01 22:05:26 Subtracting time fields
Previous Message Josh Berkus 2002-11-01 22:01:11 Re: Does this matter?