In one version of the ancient Oedipus myth, a servant of the house of King Laius of Thebes is tasked by Laius with taking the baby boy of Laius and his wife Jocasta into the mountains and leaving him there to die. This is done to avoid a prophecy of the gods that the child will one day kill his own father and marry his mother.
A shepherd finds the child in the mountains and takes pity on him. Unable to raise the child himself, the shepherd gives him to a shepherd from Corinth, who takes the child back to Corinth and gives him to childless King Polybus and Queen Merope. The other royal couple raises the child as their own.
In other versions of the myth, Laius himself takes the baby into the mountains, where a shepherd finds him. There are also variations of the story in which the baby's mother, Jocasta, gives the baby to the servant to take into the mountains, which gives a different perspective to the story and to Jocasta's character.
In Sophocles's retelling of the myth in Oedipus Rex, there is no servant who takes the child into the mountains. There is only Laius's shepherd who takes the child into the mountains, takes pity on the child, and gives the child to the shepherd from Corinth.
Sophocles further reduces the number of characters in Oedipus Rex by making the herdsman the surviving member of Laius's retinue on the day he was killed. It would make sense that a servant was part of Laius's retinue, but how the shepherd became part of the retinue is not explained. It might explain, though, why the shepherd ran away and didn't stay to fight and die with the other members of the king's retinue.
Sophocles also combines the characters of the messenger from Corinth with the shepherd from Corinth who received the baby Oedipus from Laius's shepherd. Apparently King Polybus promoted the shepherd to trusted messenger at some point in the intervening years.
By ingeniously reducing the number of characters, Sophocles simplifies the storytelling. Instead of five characters who must appear before Oedipus—Laius's servant, Laius's shepherd, sole survivor of Laius's retinue, messenger from Corinth, and shepherd from Corinth—each of whom knows only part of the story, there are only the former shepherd-become-messenger from Corinth, and Laius's shepherd, who is a combination of servant, shepherd, and surviving member of Laius's retinue.
Between them, these two characters know all of the story, making the other characters unnecessary. By eliminating and combining characters, Sophocles reduces the number of characters who must appear before Oedipus to tell their part of the story. This decision speeds up the action the play considerably.
The action of the play moves quite slowly as it is, and it would move even more slowly to the all-important anagnorisis of the play—when Oedipus realizes the truth— if five separate characters had to be identified, discussed, summoned to Oedipus's palace, brought before Oedipus, and questioned by Oedipus as to their part in the story.
Sophocles decided that it's much better—and it most certainly is—to reduce the number of characters, eliminate all of the extra dialogue he'd have to write to explain all of these characters and their part in the story, and move the play forward in the most dramatically efficient and most emotionally effective way possible.
There is also the consideration that there can be no more than three characters (plus the Chorus) in any scene at the same time. As a side note, one of Sophocles's innovations was the addition of the third speaking role in a scene.
Reducing the number of characters eliminates the potential logistical nightmare of getting all of these characters on and off the stage at the most dramatically opportune moment in the play, and minimizes the possibility of overloading the audience with information, and simply confusing them.
By the seeming coincidence of the herdsman's multiple and combined roles in Oedipus Rex, Sophocles enhanced the dramatic effect of the play, and heightened its emotional impact on the audience.