15,968,413 members
See more:
I am using subquery with Inner Join and it is returning 10 rows but i need to match those 10 rows with another table.
How can i do that.

Below is my query.
SQL
```SELECT
IT.IPTELM MOBILNO,
TC.CDGACNTN GROUPACCOUNTNO,
TC.CDCUSTN CUSTOMERNO,
TC.PRCARDN,
TC.CARDNO,
TC.CRDIND,
TC.Limit
FROM CARDS.DBO.TOTAL_CDBS11801 TC
INNER JOIN CARDS.DBO.INPARTPF IT ON
(SELECT DISTINCT CDCUSTN FROM CARDS.DBO.TOTAL_CDBS11801 WHERE PRCARDN  IN
(SELECT PRCARDN FROM CARDS.DBO.TOTAL_CDBS11801 WHERE CARDNO IN (SELECT * FROM #T)
) AND CRDIND ='P')  = (IT.IPKIPN)```

Any ideas

What I have tried:

Googled to find the solution with subquery using inner joins but could not find any solution
Posted
Updated 6-Mar-18 19:27pm
v2
Maciej Los 7-Mar-18 3:07am
Too many SELECT's!
Try to decrease the number of SELECT statement and you'll be able to correct your query.
Yes, I can see what you're doing and why it doesn't work, Peter is absolutely right.

Explain in words what you want to achieve and we might be able to help you.

## Solution 1

SQL
```(SELECT DISTINCT CDCUSTN FROM CARDS.DBO.TOTAL_CDBS11801 WHERE PRCARDN  IN
(SELECT PRCARDN FROM CARDS.DBO.TOTAL_CDBS11801 WHERE CARDNO IN (SELECT * FROM #T)
) AND CRDIND ='P')  = (IT.IPKIPN)```

What you actually have here is A = B, where A (the select clause) has multiple values... You can not do = (equal) with more than one values in either side...

Maciej Los 7-Mar-18 3:07am
Short And To The Point!
Faran Saleem 7-Mar-18 4:22am
No sir, you are wrong the issue here is not with = operator but the subquery. Subquery is returning more than one row that is why it is giving me an error. I have used the In operator aswell but it is giving the same error