Loop categories with query

Is it possible to create a query for get the categories and sub categories? I want a more advanced query for this and get_terms or get_categories is not enough for me.