query and update from SQL