Search Postgresql Archives

Re: Search for lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




[...]
> 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];


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux