Working through sql statements