Fixed broken select query