The centre of gravity of liquid columns would be at heights h1 and h2 respectively. A is area of crosssection.
Total P.E. when they are not connected
When the levels are equal, the potential energy is given as
The change in potential energy
Work done due to gravity
The negative sign shows that the work is done by the gravitational field on the liquid.