added joins to sql_query_range