0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Maven
  • 14,587
  • 42
  • 113
  • 174
  • 1
    This error tells you that there is no 'ident' field for your table tb (team_basics ) – Rogério Carvalho Batista Jan 17 '18 at 16:49
  • 2
    Possible duplicate of [The multi-part identifier could not be bound](https://stackoverflow.com/questions/7314134/the-multi-part-identifier-could-not-be-bound) – lurker Jan 17 '18 at 16:51
  • thats not true, for sure. – Maven Jan 17 '18 at 16:51
  • 1
    Use proper `JOIN` – Eric Jan 17 '18 at 16:56
  • 4
    you are mixing 2 different ways of joining tables. use explicit JOIN only. – isaace Jan 17 '18 at 16:57
  • 1
    [Bad habits to kick : using old-style JOINs](https://sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins) - that old-style *comma-separated list of tables* style was replaced with the *proper* ANSI `JOIN` syntax in the ANSI-**92** SQL Standard (**more than 25 years** ago) and its use is discouraged – marc_s Jan 17 '18 at 17:49

1 Answers1

4

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786