I am using PostgreSQL to cook the "Nested Set Model of
Trees in SQL' examples from Chapter 29 of Joe Celko's book "SQL For
Smarties".  In Section 29.3 ("Finding Levels and Paths in a Tree"),
the following query is used:

        SELECT P2.emp FROM (COUNT(p1.emp) - 1) AS level
          FROM Personnel AS P1, Personnel as P2
         WHERE P2.lft BETWEEN P1.lft AND P1.rgt;

When I run this query, I get:

ERROR:  Attribute P2.emp must be GROUPed or used in an aggregate function

When I add append GROUP BY p2.emp to the query, I no longer get the
error and the results are returned.  Why must I explicitly declare a
GROUP BY on the query?

Regards,
Jarrod



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Reply via email to