completed sql for live site