You can't do it in any automatic/magical way. What you can do is define a class that will have the union of properties of the two tables like:
public class JoinedResult{
private int id;
private int name;
// all other common properties to both
...
// properties exclusive to first table
...
// properteis exclusive to second table
...
}
and construct a list of these object that will contain the joined result of both tables.
To make the actual construction you have a few options:
- The first one and the easiest one (but not efficient) is to iterate both results with nested loops, and once the ids (or whatever key is used) match you should construct a
JoinedResult
.
- The second one is a bit more complex but also more efficient:
- Iterate first result set and construct a map that will map the id to the object.
- Iterate second result set and construct a map that will map the id to the object.
- Run a loop over the keys of one of the maps you constructed and use that key to access the matching values in both maps, finally construct the joined object.