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

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

oracle - Invalid Identifier SQL

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...