It's commonly believed that dogs wag their tails to convey that they are happy and friendly, but this isn't exactly true.
Dogs do use their tails to communicate, though a wagging tail doesn't always mean, "Come pet me!" Dogs have a kind of language that's based on the position and motion of their tails.