The right of possession of a tenant for years shall not be deemed paramount to that of a purchaser at a tax sale. The right of possession of a tenant for years shall be deemed paramount to that of a purchaser at a judicial sale if, and only if, the letting to him shall precede in point of date the entry of the judgment, order or decree on which such sale was had, and also shall precede the recording or registering of the mortgage, deed or will, if any, through which by legal proceedings the purchaser derives title, unless the letting is made with actual notice to such tenant of the contemplated entry of such judgment, order or decree, or of the fact of the execution of such mortgage, deed or other instrument of writing, and with intent to avoid the effect thereof.
68 P.S. § 342