Server shutdown in progress
SELECT DISTINCT CASE WHEN properties_loc2.name_nl_loc2 IS NOT NULL THEN properties_loc2.name_nl_loc2 ELSE province1.name_nl_loc2 END AS province, CASE WHEN properties_loc2.id_loc2 IS NOT NULL THEN properties_loc2.id_loc2 ELSE province1.id_loc2 END AS id FROM properties_loc4 towns LEFT OUTER JOIN properties_properties ON properties_properties.localidad_prop = towns.id_loc4 LEFT OUTER JOIN properties_loc3 areas1 ON towns.loc3_loc4 = areas1.id_loc3 LEFT OUTER JOIN properties_loc3 ON areas1.parent_loc3 = properties_loc3.id_loc3 LEFT OUTER JOIN properties_loc2 province1 ON areas1.loc2_loc3 = province1.id_loc2 LEFT OUTER JOIN properties_loc2 ON province1.parent_loc2 = properties_loc2.id_loc2 LEFT OUTER JOIN properties_loc1 ON province1.loc1_loc2 = properties_loc1.id_loc1 LEFT OUTER JOIN properties_loc4 ON towns.parent_loc4 = properties_loc4.id_loc4 WHERE properties_properties.activado_prop = 1 AND alquilado_prop = 0 AND vendido_prop = 0 GROUP BY id ORDER BY province ASC