| Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         man889 
                                        Starting Member 
                                         
                                        
                                        25 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2011-07-28 : 00:10:45
                                            
  | 
                                             
                                            
                                            | I have two tables as following(Table)OtherFeeType____________(Field)OtherFeeTypeId, OtherFeeTypeDes1, ParkFee2, RoadFee3, RegisterFee4, CheckFee5, OverWeightFee(Table)JobItemOtherFee_________________(Field)JobItemOtherFeeID, JobItemNo, OtherFeeTypeId, OtherFeePrice1, 1, 1, 202, 1, 2, 303, 2, 1, 104, 2, 4, 50(*No duplicate OtherFeeTypeId for the same JobItemNo)How can I write the query and have the following output?where JobItemNo = 1Output_________________OtherFeeTypeId, OtherFeeTypeDes, JobItemOtherFeeID, JobItemNo, OtherFeeTypeId, OtherFeePrice1, ParkFee, 1, 1, 1, 202, RoadFee, 2, 1, 2, 303, RegisterFee, , , ,4, CheckFee, , , ,5, OverWeightFee, , , ,where JobItemNo = 2Output_________________OtherFeeTypeId, OtherFeeTypeDes, JobItemOtherFeeID, JobItemNo, OtherFeeTypeId, OtherFeePrice1, ParkFee, 3, 2, 1, 102, RoadFee, , , ,3, RegisterFee, , , ,4, CheckFee, 4, 2, 4, 505, OverWeightFee, , , ,Thank. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     man889 
                                    Starting Member 
                                     
                                    
                                    25 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-07-28 : 02:48:28
                                          
  | 
                                         
                                        
                                          | I solved it by using derived tablesThank.SELECT OtherFeeType.OtherFeeTypeId, OtherFeeType.OtherFeeTypeDes, t1.InvNo, t1.JobId, t1.OtherFeePrice, t1.OtherFeeRemarkFROM OtherFeeType LEFT JOIN [select JobItemOtherFee.InvNo, JobItemOtherFee.JobId,  JobItemOtherFee.OtherFeeTypeId,JobItemOtherFee.OtherFeePrice, JobItemOtherFee.OtherFeeRemarkfrom JobItemOtherFeeWHERE ((JobItemOtherFee.JobId)=16)]. AS t1 ON OtherFeeType.OtherFeeTypeId= t1.OtherFeeTypeId;  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |