QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryObjectModelFactory factory = queryManager.getQOMFactory();
Selector car1Selector = factory.selector("car:Car", "car1");
Selector car2Selector = factory.selector("car:Car", "car2");
Join join = factory.join(car1Selector, car2Selector, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER,
factory.equiJoinCondition("car1", "car:maker", "car2", "car:maker"));
Column[] columns = new Column[] {factory.column("car1", "car:maker", "maker"),
factory.column("car2", "car:model", "model")};
Query query = factory.createQuery(join, null, null, columns);
QueryResult result = query.execute();
String[] columnNames = {columns[0].getColumnName(), columns[1].getColumnName()}; // the aliases