I would like to select groups that have the exact same attributes from a table. For example, my table is like the following
facs_run_id | fcj_id
1 | 17
1 | 4
1 | 12
2 | 17
2 | 4
2 | 12
3 | 17
3 | 12
3 | 10
In this table each facs_run_id has different combinations of fcj_id, some are shared between facs_run_id numbers while others are not. For example, above facs_run_id 1 and 2 are identical, while 3 has shared fcj_id but is not identical to 1 and 2. I would like to make query to:
- gather all
fcj_idfrom a particularfacs_run_id - find all
facs_run_idthat have the exact samefcj_idcombination.
Herein, I want to find all facs_run_id that are equal in fcj_id combinations to facs_run_id: 1, so it should return 2 (or 1 & 2).
I can get those that are missing certain fcj_id and even find which fcj_id are missing with this:
SELECT facs_run_id
FROM facs_panel
EXCEPT
SELECT fcj_id
FROM facs_panel
WHERE facs_run_id = 2;
or this:
SELECT row(fp.*, fcj.fcj_antigen, fcj.fcj_color)
FROM facs_panel fp
LEFT OUTER JOIN facs_conjugate_lookup fcj ON fcj.fcj_id = fp.fcj_id
WHERE fp.fcj_id in ( SELECT fp.fcj_id
FROM facs_panel fp
WHERE fp.facs_run_id = 1);
But I am not able to make a query that returns IDENTICAL facs_run_id. I suppose this could be considered a way of looking for aggregated duplicates, but I don't know how to do that. Any suggestions or pointers would be greatly appreciated (or a better way to create the table if this type of query will not work).
It's pretty easy with a couple CTEs:
The data from the question, run through this query, produces: