A relative pronoun provides usually more information about a noun that is mentioned before a COMMA. It is a product of gender (der, die, das) and singular or plural (dt. Numerus) BEFORE the COMMA, but the CASE is determined in the sentence AFTER the COMMA. Thus this can be very challenging:
There are only a few relative pronouns to choose - der, die, das, den, dem, 'der (fem. dative)', denen, dessen & deren, and was, wer, wen, wem, wessen.