public CachedRowSet joinTables(List<String> fromTables, List<NodeRelationship> whereClause, Map<String,List<String>> orderBy) throws MainException {

		String query = "";

		// Process SELECT and FROM clause at the same time
		query += "SELECT DISTINCT * FROM " + fromTables.get(0);
		for(int i=1; i<fromTables.size(); i++){
			query += ", " + fromTables.get(i);
		}

		// process where clause
		query += " WHERE ";
		Iterator<NodeRelationship> nrItr = whereClause.iterator();
		while (nrItr.hasNext()) {
			NodeRelationship nodeRel = nrItr.next();
			List<String> cols1 = nodeRel.getCols1();
			List<String> cols2 = nodeRel.getCols2();
			for(int i=0; i<cols1.size(); i++){
				query += nodeRel.getOriginalTable1() + "." + cols1.get(i) + "=" + nodeRel.getOriginalTable2() + "." + cols2.get(i);
				if(i!=cols1.size()-1){
					query += " AND ";
				}
			}

			// if it is not the last where clause
			if (nrItr.hasNext())
				query += " AND ";
		}

		logger.info("Query to execute : " + query);
		try{
			CachedRowSet crs = new CachedRowSetImpl();
			ResultSet results = executeQuery(query);
			crs.populate(results);
			return crs;
		}catch(SQLException ex){
			throw new MainException(""+ex.getMessage());
		}
	}