Bereishit (40:5), “And the two of them dreamt a dream. Each man had his dream on the same night, each man according to the interpretation of his dream—the cupbearer and the baker of the king of Egypt, who were confined in the prison.” Berachot (55b) explains that they each dreamt their dream and the interpretation of the other’s dream and that this is how the baker knew that Joseph interpreted well (Bereishit 40:15).
The cupbearer was returned to his post, but the baker was hanged. We can see that the cupbearer was a good person and that the baker was not. Since they dreamt the interpretation of the other’s dream, why did they need Joseph? The cupbearer was a good person; he did not want to reveal to his friend that he would die. The baker was a bad person; he did not want to reveal to his friend that he would live.