How compare Number with number and string

If suppose I have data like

column1	column2	
504231	504109	
504109	504201	
504201		
504299		

then I used the following formula
=IF(ISNA(VLOOKUP($A2,$B$2:$B$5,1,0)),"",VLOOKUP($A2,$B$2:$B$5,1,0)) it works fine and it producess following result

column1	column2	column3
504231	504109	
504109	504201	504109
504201		    504201
504299		

Now I have data like

column1	column2	column3
504231	 504109	smith
504109	 504201	scott
504201		
504299		

then I want ouput like

column1	column2	column3	column4	column5
504231	 504109	smith		
504109	504201	scott	   504109	  smith
504201			           504201	  scott
504299
            **OR**
column1	column2	column3
504231		
504109	504109	smith
504201	504201	scott
504299

How to acheive this output . What is the formula for this please let me know