Search code examples
sqlt-sqlsql-server-2014

LEFT JOIN: The multi-part identifier "_" could not be bound


For the below query

SELECT TOP 1000 tb.firstName
    ,tb.secondName
    ,tb.startYear
    ,nb.primaryName
    ,tr.averageScore
    ,tr.numVotes
    ,g.subjectDescription
    ,tb.isActive
FROM team_basics tb
    ,ground g
    ,info_basics nb
INNER JOIN title_ground tg ON tb.ident = tg.ident
INNER JOIN name_title nt ON tb.ident = nt.ident
LEFT JOIN title_ratings tr ON tb.ident = tr.ident
WHERE nb.nconst = nt.nconst
    AND tg.groundId = g.groundId
ORDER BY tr.averageScore DESC
    ,tb.startYear DESC;

I am getting following error:

The multi-part identifier "tb.ident" could not be bound.

Earlier these were implicit joins but trying to resolve i changed them to explicit inner joins but still I am getting this error. What can I try next?


Solution

  • Never use commas in the FROM clause. Always use proper, explicit JOIN syntax.

    So, write the FROM clause as:

    FROM team_basics tb INNER JOIN
         title_ground tg
         ON tb.ident = tg.ident INNER JOIN
         ground g
         ON tg.groundId = g.groundId INNER JOIN
         name_title nt
         ON tb.ident = nt.ident INNER JOIN
         info_basics nb
         ON nb.nconst = nt.nconst LEFT JOIN
         title_ratings tr
         ON tb.ident = tr.ident
    

    You no longer need a WHERE clause.