bridge table joined table have both the keys equal to both the keys SELECT DISTINCT i0.id,
            i0.name
FROM main_table AS i0
   RIGHT OUTER JOIN "bridge_table" AS i3 ON i3."main_table_id" = i0."id"
   RIGHT OUTER JOIN "other_table" AS r4 ON i3."other_table_id" = r4."id"


I need to get records for which other_table has name equal to both "name_1" and "name_2" or name is equal to "name_3". I have tried WHERE (r4."name" = ANY (name_1, name_2)) OR (r4."name" = name_3). it is many to many relation

I know its wrong query...
Any help will be really appreciated, thanks

Update: 

CREATE TABLE main_table
(
      id   serial PRIMARY KEY,
      name VARCHAR(50) UNIQUE NOT NULL
);

CREATE TABLE other_table
(
      id   serial PRIMARY KEY,
      name VARCHAR(50) UNIQUE NOT NULL
);


CREATE TABLE bridge_table
(
      other_table_id INT NOT NULL
              REFERENCES other_table,


      main_table_id  INT NOT NULL
              REFERENCES main_table,

      PRIMARY KEY (other_table_id, main_table_id)
);


INSERT INTO main_table(id, name) VALUES (1, 'Main 1');

INSERT INTO main_table(id, name) VALUES (2, 'Main 2');

INSERT INTO main_table(id, name) VALUES (3, 'Main 3');



INSERT INTO other_table(id, name) VALUES (1, 'Other 1');

INSERT INTO other_table(id, name) VALUES (2, 'Other 2');

INSERT INTO other_table(id, name) VALUES (3, 'Other 3');


INSERT INTO bridge_table(other_table_id, main_table_id) VALUES (1, 1);

INSERT INTO bridge_table(other_table_id, main_table_id) VALUES (1, 2);

INSERT INTO bridge_table(other_table_id, main_table_id) VALUES (2, 2);

INSERT INTO bridge_table(other_table_id, main_table_id) VALUES (3, 2);

SELECT mt.id     as mt_id,
      mt.name   as mt_name,
      ot_1.name as ot_1_name,
      ot_2.name as ot_2_name,
      ot_3.name as ot_3_name
FROM main_table AS mt
            INNER JOIN bridge_table AS bt_1 ON bt_1.main_table_id = mt.id
            INNER JOIN other_table AS ot_1 ON bt_1.other_table_id = ot_1.id

            INNER JOIN bridge_table AS bt_2 ON bt_2.main_table_id = mt.id
            INNER JOIN other_table AS ot_2 ON bt_2.other_table_id = ot_2.id

            INNER JOIN bridge_table AS bt_3 ON bt_3.main_table_id = mt.id
            INNER JOIN other_table AS ot_3 ON bt_3.other_table_id = ot_3.id
WHERE (ot_1.name = 'Other 1' AND ot_2.name = 'Other 2')
  OR (ot_3.name = 'Other 3')


I have created above sql to help generate required structure...
If I understand the task correctly, then look for

SELECT mt.id, mt.name
FROM main_table AS mt
JOIN bridge_table AS bt ON bt.main_table_id = mt.id
JOIN other_table AS ot ON bt.other_table_id = ot.id
GROUP BY mt.id, mt.name
HAVING 2 = COUNT( DISTINCT CASE WHEN ot.name IN ('Other 1', 'Other 2') THEN ot.name END )
    OR 1 = COUNT( DISTINCT CASE WHEN ot.name IN ('Other 3')            THEN ot.name END ) 


To make it dynamic use

-- constant part
HAVING 1 = 0 
-- dynamic parts
    OR (cnt_1 = COUNT( DISTINCT CASE WHEN ot.name IN ( list_1 ) THEN ot.name END ))
    OR (cnt_2 = COUNT( DISTINCT CASE WHEN ot.name IN ( list_2 ) THEN ot.name END ))
-- ...


where list_N - values list, and cnt_N - unique values count in the list.