From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: limit with subselect |
Date: | 2008-07-25 10:39:30 |
Message-ID: | 20080725103930.GK2572@frubble.xen.chris-lamb.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Jul 25, 2008 at 12:02:23PM +0200, A B wrote:
> and I wish to get 20 lines from T like this
>
> select id,a,b from T where id not in (select id from T2 where c=5) limit 20;
>
> but that does not seem to work. How can I get what I want? What 20
> records are selected is not important. I just need 20.
You've told us what you're expecting, but not what you're actually
getting so most responses (including this) are going to be guesses! More
information = better responses!
My guess is that you're not getting anything back at all because one of
the "id"s in T2 is null. If that is the case, you need to change the
query to look like:
SELECT id,a,b FROM t WHERE id NOT IN (
SELECT id FROM t2 WHERE c=5 AND id IS NOT NULL)
LIMIT 20;
Sam
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Moran | 2008-07-25 10:56:56 | Re: php + postgresql |
Previous Message | A B | 2008-07-25 10:31:56 | Re: limit with subselect |