question

IPERVEZ784 avatar image
IPERVEZ784 asked

SQL Inner Join ISSUE

I have three Tables which I want to Join . I wrote down the Inner Join Query , But It is giving me error (Error: CustNumbr is used Multiple times with D)
The SQL Query I wrote down is : Please note that I want to use all 3 conditions present in WHERE A.DOCNUMBR <> B.APTODCNM
AND A.DOCNUMBR <> B.APFRDCNM AND A.CURTRXAM <>0) d AND THE 2ND CONDITION WHERE d.DOCNUMBR <> C.DOCNUMBR AS WELL. . Please help me , where I have done mistake
SELECT * FROM (

SELECT * FROM slbReceivablesTrx A
JOIN RM20201 B
ON A.CUSTNMBR= B.CUSTNMBR
WHERE A.DOCNUMBR <> B.APTODCNM
AND A.DOCNUMBR <> B.APFRDCNM AND A.CURTRXAM <>0) d

JOIN RM20101 C
ON C.custnmbr = d.CUSTNMBR
WHERE d.DOCNUMBR <> C.DOCNUMBR

sql-server-2008-r2inner join
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered

both table A and table B have a column named CUSTNMBR. You are selecting with a wildcard rather than specifying column names, so CUSTNMBR is appearing twice in your subquery D. A subquery must return unique column names. If you specify column names, and only use CUSTNMBR from either table A or table B, your error for this column will go away

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.