private TableData join(HashMap<String, TableData> result)
	{
		//Queue<String> todo=new LinkedList<String>();
		//Queue<String> temp=new LinkedList<String>();
		
		String leftId=idsTobeJoin.remove(idsTobeJoin.size()-1);
		int index=idsTobeJoin.size()-1;
		String rightId;
		ArrayList<String> finishedId=new ArrayList<String>();
		finishedId.add(leftId);
		
		//left Table Data: 
		TableData tdLeft;//get it from result or primary table depending
		//left is primary
		boolean leftIsPrimary;
		
		if(result.containsKey(leftId))
		{
			tdLeft=result.get(leftId);
			leftIsPrimary=false;
		}
		else
		{
			tdLeft=primarytables.get(from.get(leftId));
			leftIsPrimary=true;
		}
		
		
		while( !idsTobeJoin.isEmpty())
		{
			rightId=idsTobeJoin.remove(index);
			
			//System.out.println("id "+rightId+" will be joined!\nFinishedId will contain: ");
			//join the two tables below:
			//Joins todo: get from multiTableJoins,need to search which one has it
			JoinsTodo jtd=findExpression(finishedId,  rightId);
			ArrayList<Expression> exprs;
			if(jtd==null)
			{
				idsTobeJoin.add(idsTobeJoin.size(), rightId);
				index--;
				continue;
			}
			else
			{
				exprs=jtd.getExpression();
				String id1=jtd.getID().getId1();
				//leftId=(rightId==id1)? jtd.getID().getId2():id1;
				if(rightId.equals(id1))
				{
					leftId=jtd.getID().getId2();
				}
				else
				{
					leftId=jtd.getID().getId1();
				}
				//System.out.println("Find the match: LeftId="+leftId+" RightId="+rightId);
				index=idsTobeJoin.size()-1;
			}
			
			//right Table Data: 
			TableData tdRight;
			//right is primary
			boolean rightIsPrimary;
			
			if(result.containsKey(rightId))
			{
				tdRight=result.get(rightId);
				rightIsPrimary=false;
			}
			else
			{
				tdRight=primarytables.get(from.get(rightId));
				rightIsPrimary=true;
			}
			
			tdLeft=doJoin(leftId, tdLeft, leftIsPrimary, rightId, tdRight, rightIsPrimary, exprs);
			leftIsPrimary=false;

			finishedId.add(rightId);
			/*
			Iterator<String> iter=finishedId.iterator();
			while (iter.hasNext())
			{
				System.out.println(iter.next());
			}
			*/
			
		}
		return tdLeft;
	}