Why did Jesus get baptized? I have always been taught that Jesus got baptized as an example for us. If people were getting baptized before Jesus did, then why did he need to make that an example if people were already being baptized?
Since you did not ask for a particular denomination's viewpoint, please allow me to give a Catholic perspective to this question.

The Baptism of Jesus marked the beginning of His public ministry and the wanted the faithful to not only to have an example, but He also wish to share to all our humanity at the same time and show us the way to salvation. God also used this occasion to anoint Jesus of Nazareth with the Holy Spirit and power.

What does the Gospel tell us about this event:


  Then Jesus came from Galilee to John at the Jordan, to be baptized by him. John would have prevented him, saying, "I need to be baptized by you, and do you come to me?" But Jesus answered him, "Let it be so now; for it is proper for us in this way to fulfill all righteousness." Then he consented. And when Jesus had been baptized, just as he came up from the water, suddenly the heavens were opened to him and he saw the Spirit of God descending like a dove and alighting on him. And a voice from heaven said, "This is my Son, the Beloved, with whom I am well pleased." - Matthew 3:13-17


Now let us see what St. Thomas has to say on thi subject.


  St. Thomas Aquinas, in the Summa Theologica (see ST 3, 39, 1-8), listed a number of objections, including, “It would seem that it was not fitting for Christ to be baptized. For to be baptized is to be washed. But it was not fitting for Christ to be washed, since there was no uncleanness in Him. Therefore it seems unfitting for Christ to be baptized.” His answer draws upon both Scripture and the Church Fathers: “I answer that, It was fitting for Christ to be baptized. First, because, as Ambrose says on Luke 3:21: ‘Our Lord was baptized because He wished, not to be cleansed, but to cleanse the waters, that, being purified by the flesh of Christ that knew no sin, they might have the virtue of baptism’.” 
  
  He also quoted St. Gregory Nazianzen, who had written, “Christ was baptized that He might plunge the old Adam entirely in the water.” He further noted that Jesus, in being baptized, was setting an example for everyone who would follow him and take up the cross of discipleship. After all, if the sinless Son of God would willingly enter the waters of baptism, how much more urgent is it that we sinners are washed in the waters of regeneration? 
  
  There are other reasons given, including one implicit in the sermon of St. Peter to the first Gentile convert, Cornelius, heard in today’s reading from the Acts of the Apostles: “You know the word that [God] sent to the Israelites as he proclaimed peace through Jesus Christ, who is Lord of all, what has happened all over Judea, beginning in Galilee after the baptism that John preached, how God anointed Jesus of Nazareth with the Holy Spirit and power.” 
  
  Here the emphasis is on the anointing; the Greek word is echrisen (ἔχρισεν) and the root word is chrió, from which comes the word “Christ”. And the title “Christ” is itself the Greek translation of the Hebrew word, “Messiah”, which means “anointed”. The Catechism explains that this is “the name proper to Jesus only because he accomplished perfectly the divine mission that ‘Christ’ signifies. In effect, in Israel those consecrated to God for a mission that he gave were anointed in his name. This was the case for kings, for priests and, in rare instances, for prophets. This had to be the case all the more so for the Messiah whom God would send to inaugurate his kingdom definitively” (par. 436). Jesus was anointed by the Holy Spirit and presented as uniquely fulfilling the threefold office of prophet, priest, and king. - Was it fitting and necessary for Jesus to be baptized?