Fixing sql