There are two different languages withing the same language family (Sino Tibetian). Pronunciation is very different. Syntax is similar. You can compare it maybe like English and Dutch, which are also in the same root language group.
If you speak one, it is easier to learn the other one.
You can say, Mandarin is the most widely spoken Chinese language INSIDE China. Cantonese is the most widely spoken China language OUTSIDE China. Most overseas Chinese communities speak Cantonese.
The writing is different too. Many mandarin expressions don't exist in Cantonese. If you want to learn writing then it is better to just learn it from Mandarin.
Interestingly, not many people in China are Mandarin native speakers. Most speak it as 2nd or 3rd language. Less then 10% of people in the PRC speak Mandarin at home.