Adding SQL for the distance table