We help IT Professionals succeed at work.
Get Started

I need two queries merged/combined

74 Views
Last Modified: 2016-03-09
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))
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE