From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Steve Clark <steve(dot)clark(at)netwolves(dot)com> |
Cc: | pgsql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: dumb question |
Date: | 2016-06-02 17:23:20 |
Message-ID: | CAKFQuwaDXFvGoycgH5BfcHuwjy3Q92DFdU_iBsCOrFdbvJS55Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thursday, June 2, 2016, Steve Clark <steve(dot)clark(at)netwolves(dot)com> wrote:
> Hi List,
>
> I am a noob trying to do something that seems like it should be easy but I
> can't figure it out.
>
> I have a table like so:
>
> id | ref_id | sts
> ------------------
> 1 | | 0
> 2 | 1 | 1
> 3 | | 0
> 4 | | 0
> 5 | 4 | 1
> 6 | | 0
> 7 | 6 | 1
>
> I want to find the max(id) whose sts is 0 but whose id is not referenced
> by ref_id.
>
> so the answer would be id=3.
>
> Thanks for any pointers,
> Steve
>
>
So, of all the rows whose sts is 0 and the id is not in (or not exists)
ref_id....subquery for selection
Give me the maximum id...parent query with group by.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2016-06-02 17:23:52 | Re: dumb question |
Previous Message | Steve Clark | 2016-06-02 17:16:06 | dumb question |