Select query generates table