Added failed attempt at optimising sql