Hi Simon,
The tables and sample data are below.
So first I search the nodes table for a and b, getting the node_id of them (in this example, 1 and 2).
Then using the SQL statement, I would get all posts that have 1 and 2 as the node_id. So in the example data, 100, 103, 108 will be returned as these posts contain the nodes 1 and 2.
Hope this helps.
DesmondÂ
-------------
CREATE SEQUENCE IF NOT EXISTS nodes_id_seq;
CREATE TABLE "public"."nodes" (
  "id" int8 NOT NULL DEFAULT nextval('nodes_id_seq'::regclass),
  "project_uuid" uuid NOT NULL,
  "topic" varchar(20) NOT NULL,
  PRIMARY KEY ("id")
);
CREATE SEQUENCE IF NOT EXISTS posts_id_seq;
CREATE TABLE "public"."posts" (
  "id" int8 NOT NULL DEFAULT nextval('posts_id_seq'::regclass),
  "project_uuid" uuid NOT NULL,
  PRIMARY KEY ("id")
);
CREATE TABLE "public"."pn" (
  "post_id" int8 NOT NULL,
  "node_id" int8 NOT NULL,
  PRIMARY KEY ("post_id","node_id")
);
INSERT INTO "public"."nodes" ("id", "project_uuid", "topic", "size", "given_id") VALUESÂ
('1', '42a8e275-f153-452b-99d3-645bdd513ca9', 'a'),
('2', '42a8e275-f153-452b-99d3-645bdd513ca9', 'b'),
('3', '42a8e275-f153-452b-99d3-645bdd513ca9', 'c'),
('4', '42a8e275-f153-452b-99d3-645bdd513ca9', 'd')
INSERT INTO "public"."posts" ("id", "project_uuid") VALUESÂ
('100', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('101', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('102', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('103', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('104', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('105', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('106', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('107', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('108', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('109', '42a8e275-f153-452b-99d3-645bdd513ca9'),
('110', '42a8e275-f153-452b-99d3-645bdd513ca9')
INSERT INTO "public"."pn" ("post_id", "node_id") VALUESÂ
('1', '100'),
('2', '100'),
('3', '100'),
('2', '101'),
('3', '101'),
('4', '101'),
('5', '101'),
('3', '102'),
('4', '102'),
('1', '103'),
('2', '103'),
('3', '103'),
('2', '104'),
('4', '104'),
('1', '105'),
('4', '105'),
('3', '105'),
('3', '106'),
('4', '106'),
('4', '107'),
('1', '108'),
('2', '108'),
('3', '109'),
('1', '109'),
('4', '109'),
('2', '110'),
('3', '110')
ALTER TABLE "public"."posts" ADD FOREIGN KEY ("project_uuid") REFERENCES "public"."projects"("uuid");
ALTER TABLE "public"."pn" ADD FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id");
ALTER TABLE "public"."pn" ADD FOREIGN KEY ("node_id") REFERENCES "public"."nodes"("id");