Fixed broken sql