Select unique value pairs based on two participants that occur more than once inside a table
CREATE VIEW uniqueness (id, User_id1, User_id2)
AS
SELECT MIN(id), 
       LEAST(User_id1, User_id2) User_id1,  
       GREATEST(User_id1, User_id2) User_id2
GROUP BY LEAST(User_id1, User_id2),  
         GREATEST(User_id1, User_id2);


and then

INSERT INTO Chat_rooms (id) SELECT id FROM uniqueness;


and

INSERT INTO Participants (chat_id, user_id)
SELECT id, User_id1 FROM uniqueness
UNION ALL
SELECT id, User_id2 FROM uniqueness;




You may create temporary table instead of view

-- or --

You may insert view's source text into INSERT queries