Help Combing Two Queries


Help Combing Two Queries

Hi there - very novice at SQL.  Looking to combine two queries and not sure how to go about. I am trying to add company_name to Query 1.  company_name is in Query 2 which uses two entirely different tables.  Of course, I am at a loss here.  Appreciate any assistance!  Thanks in advance!

Query 1 uses: 

- se_qba = pulls customer data  * NEED TO LINK cust_acct_nbr to cvmH table *

- employee_assignment AND employee = pulls employee data

Query 2 uses:

- cvmH AND cvmE = pulls company name * NEED TO LINK cust_acct_nbr from cvmH table to se_qba table *

Query 1:  Returns customer data and employee data.  Does not return customer name.

TRIM (a.sales_div_nbr) || '-' || TRIM (a.sales_grp_nbr) || '-' || TRIM (a.sales_org_nbr)  || '-' || TRIM (a.sales_rgn_nbr)  || '-' || TRIM (a.sales_area_nbr)  || '-' || TRIM (a.sales_dist_nbr) || '-' || TRIM (a.sales_terr_nbr) AS Territory,
b.first_nm || ' ' || b.last_nm AS name

from  se_qba seqba
left join employee_assignment a on seqba.sale_terr_cd = Territory
left join employee b on a.emp_nbr = b.emp_nbr

where a.exp_dt ='05/31/2525'
and seqba.cust_acct_nbr in ( '999999999' )
and seqba.sale_terr_globl_rgn_cd = 'CAN'
and align_type_cd = 'P'

Query 2:  Returns customer name.


from cpv_db.cvmH a
left join cpv_db.cvmE b on a.cvm_nbr = b.cvm_nbr

where cust_acct_nbr = '999999999'
and CURRENT_TIMESTAMP between a.eff_tmstp and a.expr_tmstp

Re: Help Combing Two Queries

Can you share the DDLs of both these tables?


Re: Help Combing Two Queries

Hi there Khurram...sorry...I am not exactly sure what you are looking for.  Could you please elaborate?  Thanks!