Re: limit with subselect - Mailing list pgsql-general

From Sam Mason
Subject Re: limit with subselect
Date
Msg-id 20080725103930.GK2572@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to limit with subselect  ("A B" <gentosaker@gmail.com>)
List 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

pgsql-general by date:

Previous
From: "A B"
Date:
Subject: Re: limit with subselect
Next
From: Bill Moran
Date:
Subject: Re: php + postgresql