fix sql for reference