added sql for top/bottom/middle questions