select function implimintation