Don't know about PS4/PS5 version, but I can tell you it is like that on the Xbox side: you can have the Xbox One version installed on an external HDD drive, and have the Series X/S install on the internal SSD drive. That allows you to play both. But players on the "lower" version only play against users who have the same version, while players on the "higher" version play users on that version.
Pretty sure it's the same way on the Sony side.