The relative pronoun who is only used to refer to people. Which is only used to refer to animals or objects. That can be used to refer to both people and objects. In some cases, that is preferred to which.
Cases where only that is possible
That should be used after superlative adjectives and other determiners like all, same, any, none, nothing, only, everything little, much and no.
- He is the same guy that picked my pocket yesterday. (More natural than ‘He is the same guy who picked my pocket yesterday.’)
- This is the best book that was ever written about World War II. (NOT This is the best book which was ever written about World War II.)
- None that participated in the contest won the prize. (More natural than ‘None who participated in the contest won the prize.’)
After all, everyone, everybody, no one, nobody and those, both that and who can be used.
- Everyone who / that participated in the competition performed well.
- All the candidates who / that wrote the exam made it to the rank list.
That should be used after the interrogative pronouns what, which and who.
- What is the problem that worries you the most? (NOT What is the problem which worries you the most?)
- Which is the phone that you would like to buy?
- Who is the writer that you like the most?
Who and whom
Whom should be used after a preposition.
- The girl to whom you spoke is my cousin. (NOT The girl to who you spoke is my cousin.)
- The girl from whom you collected the books has called me.