The supposed discrepancy between 1 Samuel 17, in which David kills the Philistine Goliath, and 2 Samuel 21:19, in which Elhanan kills Goliath, may be solved in a couple different ways.
First, we must consider the text in 1 Chronicles 20:5, that adds more information to and clarifies the claim about Elhanan in 2 Samuel 21:19. In the Chronicles text, we learn that Elhanan actually kills Lahmi the brother of Goliath.
Another possible explanation for the so-called discrepancy centers around the name Goliath. Scholars have suggested that this is not a personal name at all but rather a title for a class of warriors. A recent archeological discovery has revealed the name “Goliath” on a piece of pottery that dates from about a century after David. Obviously, there was more than one person named Goliath, and scholars now think that the term refers to a specialist group of warriors that may have been highly skilled, especially large in stature, or both. In this case, David killed one member of this Goliath group, and Elhanan killed another. Therefore, there is no discrepancy.
The author of 1 and 2 Samuel certainly did not feel that the “discrepancy” was any difficulty at all, and more than likely the text's original audience would have been aware of the original situation. Both stories combine to emphasize both the military prowess of David and his men as well as their reliance on God as their ultimate strength and power. With God behind them, they are strong enough to defeat even the elite warriors called “Goliath.”