Re: Search for lists

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: daron(dot)ryan(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Search for lists
Date: 2011-06-20 01:14:41
Message-ID: 4DFE9F01.8080901@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


[...]
> I need to search a table to find sets of rows that have a column
matching
> itself for the whole set and another column matching row for row with a
> list I am going to supply. The result I should receive should be
value of
> the column that matches itself.
[...]

How about:

DROP TABLE IF EXISTS T;

CREATE TABLE T
(
id int,
val int
);

INSERT INTO T (id, val) VALUES
(3, 1),
(3, 2),
(4, 8),
(4, 9),
(4, 10);

SELECT
id
FROM
T
GROUP BY
id
HAVING
array_agg(val) = ARRAY[8, 9, 10];

Browse pgsql-general by date

  From Date Subject
Next Message Amitabh Kant 2011-06-20 02:08:40 Re: PostgreSQL 8.4.8 bringing my website down every evening
Previous Message Cédric Villemain 2011-06-19 20:33:16 Re: PostgreSQL 8.4.8 bringing my website down every evening