finishing the sql part