SQL Procedure Syntax Part II

ok so I got some help with this SQL syntax earlier but now I need help adding an INNER JOIN to this. I'm new to the SQL writing so I'm trying to understand how to write some of the JOIN statements. The INNER JOIN that I have in there isn't correct and I'm trying to figure out why. Any help would be greatly appreciated!

	SELECT dbo.jomast.fcompany, dbo.joitem.fjobno, dbo.joitem.fpartno, dbo.joitem.fgroup, dbo.joitem.fmqty, dbo.joitem.fmeasure, dbo.joitem.fprodcl, dbo.joitem.fdesc, dbo.jodbom.fbompart, dbo.jodbom.fbomdesc, dbo.jodbom.fqty_iss FROM dbo.jodbom 
LEFT JOIN dbo.joitem ON dbo.joitem.fjobno = dbo.jodbom.fjobno 
INNER JOIN dbo.joitem ON dbo.joitem.fjobno = dbo.jomast.fjobno
WHERE ((dbo.joitem.fprodcl = '01') OR (dbo.joitem.fprodcl = '04') ) AND ((dbo.joitem.fpartno <> 'INDIRECT LABOR') OR (dbo.joitem.fpartno <> 'NOT CLOCKED'));

Open in new window

LVL 1
Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark ElySenior Coldfusion DeveloperCommented:
rough draft ... you missed the join for jomast


SELECT J3.fcompany, J1.fjobno, J1.fpartno, J1.fgroup, J1.fmqty, J1.fmeasure, J1.fprodcl, J1.fdesc, J.fbompart, J.fbomdesc, J.fqty_iss
FROM dbo.jodbom AS J
      LEFT JOIN dbo.joitem AS J1
             ON J.fjobno = J1.fjobno
     INNER JOIN dbo.joitem AS J2
            ON J1.fjobno = dJ2.fjobno
     INNER JOIN dbo.JoMast AS J3
            ON J.fjobno = J3.fjobno
WHERE ((J1.fprodcl = '01') OR (J1.fprodcl = '04') ) AND
            ((J1.fpartno <> 'INDIRECT LABOR') OR (J1.fpartno <> 'NOT CLOCKED'));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>The INNER JOIN that I have in there isn't correct
Tell us in simple English what your definition of 'correct' is for your situation.  Mind readers we ain't.

>LEFT JOIN dbo.joitem
>INNER JOIN dbo.joitem
For starters (and in Mark's code above), you're referencing table dbo.joitem twice, so when columns are referenced in the SELECT or WHERE clause it doesn't know which 'copy' to use.   In these situations, you'll need to use an alias (J1 and J2 in above code), then everywhere else in the statement use J1. and J2.
0
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Thanks Mark. I appreciate your quick response!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.