| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Julien Cigar <jcigar(at)ulb(dot)ac(dot)be> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: ALL() question |
| Date: | 2007-11-14 11:56:46 |
| Message-ID: | 473AE27E.6050103@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Julien Cigar wrote:
>
> What I would like is a query that returns all the specimen_id of
> this table which have _all_ the given test_bit_id.
[snip]
> With the following I got a syntax error:
> select specimen_id
> from specimen_test_bits
> where test_bit_id = all(1,2,3,4);
It's expecting an array here. You'd have to write
= all('{1,2,3,4}')
But that would have the same problem as...
> 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));
It's testing each row individually and of course one row can't match ALL
four values.
What you want to do is count the distinct values. Something like:
SELECT
specimen_id
FROM foo
GROUP BY
specimen_id
HAVING
count(distinct test_bit_id) = 4
;
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Aarni Ruuhimäki | 2007-11-14 12:39:13 | Re: Originally created and last_mod by whom and when ? |
| Previous Message | Richard Huxton | 2007-11-14 11:28:55 | Re: Originally created and last_mod by whom and when ? |