updated (fixed) sql