Re: [SQL] CTEs and re-use - Mailing list pgsql-sql

From Rosser Schwarz
Subject Re: [SQL] CTEs and re-use
Date
Msg-id CAFnxYwhpbiPJo6-To8oHw5NgA3TvaA2EUxma=QjjYDVvAB2ZQA@mail.gmail.com
Whole thread Raw
In response to [SQL] CTEs and re-use  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: [SQL] CTEs and re-use  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-sql
On Tue, Apr 11, 2017 at 5:41 PM, Rob Sargent <robjsargent@gmail.com> wrote:
I have a lovely little CTE/select doing exactly what I need it to do.  Unfortunately I need its results in the next query.

Can't you just chain the CTEs? E.g.,

with segset as (
--...
)
, optmarkers as (
select m.id as mkrid
--... 
  group by m.id
)
select s.id, o.optval, min(m.basepos) as firstbase
  from optmarkers o 
--...
  order by firstbase;

No temp table to drop.

rls

--
:wq

pgsql-sql by date:

Previous
From: Rob Sargent
Date:
Subject: Re: [SQL] CTEs and re-use
Next
From: Rob Sargent
Date:
Subject: Re: [SQL] CTEs and re-use