updated sql for api db