reduce SQL of sidebar in courses page