Updated sql to match new db structure