Link to home
Start Free TrialLog in
Avatar of K_Deutsch
K_Deutsch

asked on

I need two queries merged/combined

My preference is one query and not two, so I need someone to combine the query named _1 (which pulls SSNs from two different fields) and looks like this

SELECT NAMAST.SOC_SEC_NO_9 AS SSN
FROM MASTER_ALL INNER JOIN NAMAST ON (MASTER_ALL.APP = NAMAST.APP) AND (MASTER_ALL.ACCTNO = NAMAST.ACCTNO)
WHERE (((NAMAST.SOC_SEC_NO_9)<>0) AND ((MASTER_ALL.ALL_CUR_BAL_21)>0));

UNION SELECT NAMAST.SECOND_SSN_213 AS SSN
FROM MASTER_ALL INNER JOIN NAMAST ON (MASTER_ALL.ACCTNO = NAMAST.ACCTNO) AND (MASTER_ALL.APP = NAMAST.APP)
WHERE (((NAMAST.SECOND_SSN_213)<>0) AND ((MASTER_ALL.ALL_CUR_BAL_21)>0));

With this one (which for each SSN pulls a zip code from another table)

SELECT [_1].SSN, CIFHSHLD.CIFH_SEQ, CIFHSHLD.CIFH_ZIP
FROM (_1 INNER JOIN CIFMASTR ON [_1].SSN = CIFMASTR.CIFM_NBR) INNER JOIN CIFHSHLD ON CIFMASTR.CIFM_HSHLD_NBR = CIFHSHLD.CIFH_HSHLD_NBR
WHERE (((CIFHSHLD.CIFH_SEQ)=0))
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of K_Deutsch
K_Deutsch

ASKER

Let's start over and see if this time I provide enough info to get to one query. See attached.
Sample-Table-Data.xlsx
Our role isn't really to do it for you, but rather to help you do it yourself. Pat gave you some very good guidelines for a UNION query - try to put those together, and post back here with the results.