Results 1 to 2 of 2

Thread: Combining 2 select queries

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    58

    Question Combining 2 select queries

    Hello,

    I have 2 queries. they both return some values and those values are connected with each other. i need to combine both of these . how do i do that?

    1st query:
    Code:
    SELECT 
    		M.RegionCode,
    		 
    		M.ProgramType,		
    		SUM(E.Amount) AS ActualsNonReconciled,
    		Count(Distinct M.MeetingID) AS ActNonRecNoOfMtgs	
    	FROM
    		Expenses E, 
    		Meetings M,
    		Users U
    	WHERE
    		E.MeetingID = M.MeetingID AND
    		
    		M.FinancialsReconciled = 0 AND
    		M.SubCompanyCode = U.SubCompanyCode AND
    		M.PointPerson = U.Username AND
    		M.SubCompanyCode = 'abc' AND
    		M.ProgramCode = 'def' and
      M.PointPerson =  'G1AA'
    Group BY
    	      M.RegionCode,
    M.ProgramType
    result:
    Code:
    RegionCode   ProgramType   ActualsNonReconciled     ActNonRecNoOfMtgs
    G1A	       Meetings	  4565.00	                             2
    G1P	       Meetings	  65.00	                             1
    G2C	       Meetings	  1200.00	                             1

    2nd query:
    Code:
    SELECT 
    				
    		SUM(EE.Amount) AS EstimatesNonReconciled		
    		FROM
    			Expenses E, 
    			Meetings M,
    			EstimatedExpenses EE
    	
    		WHERE
    			E.MeetingID = M.MeetingID AND
    		
    			M.SubCompanyCode *= EE.SubCompanyCode AND
    			M.ProgramCode *= EE.ProgramCode AND	
    			M.ProgramType *= EE.ProgramType AND	
    			M.ServiceLevel*= EE.ServiceLevel AND		
    			E.ExpenseType *= EE.ExpenseType AND
    			M.SubCompanyCode = 'abc' AND
    			M.ProgramCode = 'def' AND
    			  M.PointPerson =  'G1AA'and
    			E.Amount = 0
    Group BY
    	M.RegionCode
    result:
    Code:
    EstimatesNonReconciled
    30.88
    1872.44
    2745.19
    my result after combining both should be:

    Code:
    RegionCode   ProgramType   ActualsNonReconciled     ActNonRecNoOfMtgs
    G1A	       Meetings	  4565.00	                             2
    G1P	       Meetings	  65.00	                             1
    G2C	       Meetings	  1200.00	                             1
    
    EstimatesNonReconciled
    30.88
    1872.44
    2745.19
    Please help.
    Last edited by si_the_geek; Jan 23rd, 2007 at 12:35 PM. Reason: added Code tags for readability

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width