I always confuse these both. When should we actually use them in a sentence?
"Which" in this sense is a word for building up a relative clause, for example:
"John brought me a car, which is my favorite."
The word "in" is not part of this unit, rather it belongs to another unit in a sentence, for example:
"John brought me a car, in which I found my computer."
This is equivalent to saying "I found my computer in a car. John brought me the car." Therefore the word "in" is a preposition linking "computer" and "car". In cases like this, we put "in" before "which".
One more complicated example,
"John brought me a car, the price of which surprised me."
It means "The price of the car surprised me."