What do you mean with comparing?
Entity A and entity B contains different attributes, so comparing apples with pears.
If you what to show the reference/associated objects/entities i.e. showing the orderlines of an order then step away of your existing knowledge on how to build the SQL yourself. That Mendix handling for you. Try to think as I described it in first sentence: showing the associated list (entity B/Orderlines) of the main object (Entity A/Order).
In that case; add a dataview with context object/entity A, add a list into the dataview with contecxt objects/entity B and use the association as path on the datasource