Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.
Jörgen Andersson 7-Mar-18 15:56pm    
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.

1 solution

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...
 
Share this answer
 
Comments
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900