pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chad Thompson <chad@weblinkservices.com>
To: Peter T. Brown <peter@memeticsystems.com>
To: pgsql-sql@postgresql.org
Subject: Re: making queries more effecient
Date: Fri, 1 Nov 2002 15:04:42 -0700
Message-ID: <033301c281f2$aed1f7e0$32021aac@chad> (raw)
References: <1036189492.2013.16.camel@localhost.localdomain>

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@memeticsystems.com>
To: <pgsql-sql@postgresql.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@postgresql.org so that your
> message can get through to the mailing list cleanly
>




view thread (4+ messages)  latest in thread

Message-ID: <033301c281f2$aed1f7e0$32021aac@chad>
Permalink:  ../033301c281f2$aed1f7e0$32021aac@chad/
Also on:    postgresql.org/message-id/033301c281f2$aed1f7e0$32021aac@chad

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chad@weblinkservices.com, peter@memeticsystems.com
  Subject: Re: making queries more effecient
  In-Reply-To: <033301c281f2$aed1f7e0$32021aac@chad>

* 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