Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So i have this:

SELECT p.plantnaam,o.levcode,o.offerteprijs
FROM plant p, offerte o
JOIN (SELECT plantcode , MIN(offerteprijs) AS offprijs 
      FROM offerte
      GROUP BY plantcode) s
  ON s.plantcode = p.plantcode
  AND s.offprijs = o.offerteprijs
ORDER BY p.plantnaam,l.levcode

Appearently on the 6th row, p.plantcode is suddenly magically an invalid identifier. Why is this? and why are all the others from the exact same table perfectly fine before that point?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem is that you are mixing JOINs. You have both implicit and explicit joins. The explicit JOIN syntax with the ON clause has a higher precedence over the implicit join with the commas. As a result the alias for the plant and the offerte tables will not be available in the ON clause. Try using the same JOIN type throughout:

SELECT p.plantnaam, o.levcode, o.offerteprijs
FROM 
(
  SELECT plantcode , MIN(offerteprijs) AS offprijs 
  FROM offerte
  GROUP BY plantcode
) s
INNER JOIN plant p
   ON s.plantcode = p.plantcode
INNER JOIN offerte o
   ON s.offprijs = o.offerteprijs
ORDER BY p.plantnaam, l.levcode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...