Fix inner join sql