Clean up and dividing of InheritsFrom functions in query-interface

Added sample output SQL query.