ο οποίος after a Preposition
There is one place που simply CANNOT be used: directly after a preposition. You cannot say «ο άντρας με που μιλάω». Here Greek REQUIRES ο οποίος, and the preposition takes it in the accusative (or the case that preposition governs): ο άντρας με τον οποίο μιλάω (“the man with whom I speak”), η πόλη στην οποία μένω (“the city in which I live”), οι φίλοι για τους οποίους γράφω (“the friends about whom I write”). The pattern is preposition + article + οποίος, all agreeing with the antecedent in gender and number: με τον οποίο, στην οποία, για τους οποίους. So whenever a relative would follow με, σε (στο/στη), από, για, χωρίς… reach for ο οποίος, never που. (Everyday speech often dodges this by rewording, but for “with whom / in which” ο οποίος is the clean, correct choice.)
The rule
There is one place που simply cannot go: directly after a preposition. «ο δάσκαλος με που μιλάω» is not Greek. There you must use ο οποίος, and the preposition puts it in the case it governs - the accusative, for the everyday prepositions: ο δάσκαλος με τον οποίο μιλάω, η πόλη στην οποία μένω, οι φίλοι για τους οποίους γράφω. The pattern is always preposition + article + οποίος, with the article and the pronoun agreeing with the antecedent in gender and number while the preposition fixes the case. So whenever a relative would land after με, σε (στον / στη(ν) / στο), από, για or χωρίς, reach for ο οποίος. Everyday speech often dodges the construction by rewording the sentence, but for “with whom / in which” this is the clean, correct choice.