In every case in which different liens are asserted against any property, the court in the judgment must declare the rank of each lien, or class of liens, which shall be in the following order, viz:
A. all persons other than the original contractors and subcontractor;
B. the subcontractors;
C. the original contractors.
And the proceeds of the sale of the property must be applied to each lien, or class of liens, in the order of its rank, and whenever, on the sale of the property subject to the lien, there is a deficiency of proceeds, judgment may be docketed for the deficiency in like manner, and with like effect as in actions for the foreclosure of mortgages.