pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>
To: Julien Cigar <jcigar@ulb.ac.be>
Cc: pgsql-sql@postgresql.org
Subject: Re: ALL() question
Date: Wed, 14 Nov 2007 13:46:35 -0200
Message-ID: <473B185B.2050502@yahoo.com.br> (raw)
In-Reply-To: <1195047542.3190.9.camel@frodon.be-bif.ulb.ac.be>
References: <1195047542.3190.9.camel@frodon.be-bif.ulb.ac.be>

Julien Cigar escreveu:
> Hello,
> 
> I have a problem with the ALL() subquery expression.
> I have three tables:
> - specimens
> - test_bits
> - specimen_test_bits
> 
> The specimen_test_bits table contains two foreign keys, one to
> specimens(id), another to test_bits(id). 
> 
> Here is an output of specimen_test_bits:
> 
> muridae=> select * from specimen_test_bits;
>  specimen_id | test_bit_id 
> -------------+-------------
>        46096 |           1
>        46096 |           2
>        46096 |           3
>        46096 |           4
>        52894 |           1
>        52894 |           3
>        12546 |           2
> 
> What I would like is a query that returns all the specimen_id of 
> this table which have _all_ the given test_bit_id. So in this
> case, with test_bit_id 1,2,3,4 it should return only 
> specimen_id 46096.
> 
> With the following I got a syntax error:
> select specimen_id 
> from specimen_test_bits 
> where test_bit_id = all(1,2,3,4);
> 
> The following works but no rows are returned :
> select specimen_id 
> from specimen_test_bits 
> where test_bit_id = all(select id from test_bits where id in (1,2,3,4));
> 
> Any idea how I could do this ? I guess the problem is my ALL() expression ...
> 


Unclear, but works...

SELECT DISTINCT stb.specimen_id FROM specimen_test_bits stb
  WHERE NOT EXISTS (SELECT * FROM (VALUES (1), (2), (3) , 
(4)) AS foo(id)
                     WHERE NOT EXISTS (SELECT 
stb1.test_bit_id FROM specimen_test_bits stb1
                                        WHERE foo.id = 
stb1.test_bit_id
                                          AND 
stb.specimen_id = stb1.specimen_id));

Osvaldo



view thread (10+ messages)  latest in thread

Message-ID: <473B185B.2050502@yahoo.com.br>
Permalink:  ../473B185B.2050502@yahoo.com.br/
Also on:    postgresql.org/message-id/473B185B.2050502@yahoo.com.br

 · 

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: osvaldo_kussama@yahoo.com.br, jcigar@ulb.ac.be
  Subject: Re: ALL() question
  In-Reply-To: <473B185B.2050502@yahoo.com.br>

* 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