0

I know that I have seen a couple of other questions about this error but I'm new to the sql JOIN so plz could you guy explain what I'm doing wrong.

Here's my query

SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs` 
FROM `Klanten`, `kaart` 
LEFT JOIN (`Intro`) 
ON (Intro.KlantNummer = Klanten.Klantnummer) 
WHERE kaart.KlantNummer = Klanten.Klantnummer

This is the Error I get like you have seen in the title

1054 - Unknown column 'Klanten.Klantnummer' in 'on clause'

And the db names are correct

Community
  • 1
  • 1
  • 2
    well, does the `Klanten` table have a `Klantnummer` column? – Lamak Dec 12 '16 at 21:09
  • A side note, but you really shouldn't mix both the implicit and explicit `JOIN` styles. In fact, you really shouldn't even have a `,` in the `FROM` clause at all. That style became obsolete **nearly 25 years ago.** – Siyual Dec 12 '16 at 21:12

1 Answers1

2

Simple rule: Never use commas in the FROM clause. Always use proper, explicit JOIN syntax. If you did that, you would not have an error:

SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs` 
FROM `Klanten` JOIN
     `kaart`
     ON kaart.KlantNummer = Klanten.Klantnummer LEFT JOIN 
     `Intro`
     ON Intro.KlantNummer = Klanten.Klantnummer ;

The problem is that the precedence of , and JOIN are different. Hence, the table before the comma is not known to the ON clause.

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