Fix sql printing and selection