Yarns have different fibre contents (eg: lambswool, alpaca, synthetic) and sometimes are blended (eg. wool/silk).
They also come in different 'grists' (thicknesses) so you can find the right yarn for the right pattern.
When you buy a commercial knitting pattern, it will specify a certain yarn. But that is only because the patterns are published to sell yarn. You can easily check the weight (thickness, eg: whether 4 ply, DK, Aran, Chunky) of the yarn, and the length of the yarn in that ball or skein, then substitute something similar, that you prefer. So long as you then knit a tension square and change your needle size, if needed, to get the right tension for your pattern.
I sometimes design and write knitting patterns and like other independent designers, will simply use the yarn I like best for the job so I am not tied to any one manufacturer. Even so, people knitting my stuff could easily substitute so long as they are well informed (That's where the 'Yarns' tab on www.ravelry.com comes in handy).
Generally the fatter a wool (eg; Aran, chunky) the faster it is to knit something from it, but the less yardage you will get from a ball of the same weight. So a 50g ball of laceweight yarn would be a lot longer than a 50g ball of Aran.
So you can choose your yarns for alll kinds of reasons - according to the pattern you're knitting, whether it's for summer or winter, what qualities you want the finished item to have, how fast it is to knit, how great the colour range is... and a million other reasons.
If I'm not sure about a yarn, I go to Ravelry and check it out as people leave honest reviews and comments, and there are links to blogs etc as wlel as people's projects, where they may forewarn you about problems (ie: this skein had loads of knots in it) and also the positives (eg: how well it washes).