SELECT * FROM (SELECT * FROM userroom WHERE userId = 1 LIMIT 2) AS ur LEFT OUTER JOIN room ON room.id = ur.roomId LEFT OUTER JOIN message msg ON msg.id IN (SELECT m