This is a Hebrew textual question. The Masoretic text of 2 Samuel 21:19 is missing the words the brother of.
The context of 2 Samuel 21 shows that this is a different event and time and that it refers to the brother of Goliath. Therefore David killed Goliath and Elhanan later killed Goliath’s brother. 1 Chronicles 20:5 confirms this.