Both which and that can function as relative pronouns. That is only used in defining relative clauses while which can be used in both defining and non-defining clauses.
That can be used to refer to both objects and persons.
Which is not used for persons.
– The girl that you saw at the party is my sister. (defining clause)
– I’ve never read the book which is on the table. (defining clause)
– Pride and Prejudice, which was written by Jane Austen, is a great novel. (non-defining clause)
In a non-defining clause, which can refer to either a word or the whole meaning of the main clause:
– We love spending our holidays in my aunt’s house, which is by the seaside.
– One of the weakest jockeys came first in the horse race, which was a surprise to everyone.
In a defining clause, both that and which can occur:
– Please give me the book that my sister lent you last week.
– Please give me the book which my sister lent you last week.
However, only that (or the zero pronoun) should be used with reference to
1. indefinite pronouns or structures with indefinite pronouns:
– Everything that you do will be remembered.
– She cooked all the potatoes that were in the basket.
– I’ll tell you something that will shock you.
– I can’t find some of my T-shirts; I wish I could find the one that has yellow sleeves.
– The police examined each bag that was left in the locker.
2. superlative adjectives or phrases with superlative adjectives:
– This is the best film that I’ve ever seen.
– The most important thing that you must always keep in mind is honesty and hard work.
3. (phrases with) ordinal numbers:
– A book is the first that I would take to a desert island.
– The third excursion that we made in the mountains was a failure.
4. the only…, thing, etc.
– The only music that I really like is rock and roll.
– Tell me a thing that you never forget to do.
If there is a preposition before the pronoun, only which can be used:
– This is the house in which Beethoven was born.
– (This is the house that Beethoven was born in.)
– Do you remember the park opposite which we stayed in London?