Search Postgresql Archives

Re: Left join syntax error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Erik Wienhold <ewie@xxxxxxxxx> writes:
> But I wonder if the implicit cross join syntax ("FROM peoples, companies")
> should actually produce this error because the explicit cross join
> works:

>     SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, c.company_name
>     FROM people as p
>         CROSS JOIN companies as c
>         LEFT JOIN companies ON c.company_nbr = p.company_nbr;

> But I'm not even sure if implicit and explicit cross join are
> semantically equivalent.

Well, they do the same thing, but JOIN binds tighter than comma.
So in one case you have effectively

    FROM people as p CROSS JOIN
         (companies as c LEFT JOIN companies ON c.company_nbr = p.company_nbr)

and "p" is not within the scope of the JOIN/ON clause.
The other way is effectively

    FROM (people as p CROSS JOIN companies as c)
         LEFT JOIN companies ON c.company_nbr = p.company_nbr;

which is syntactically legal, although it probably doesn't do
what you wanted.

If memory serves, MySQL got this basic syntactic detail wrong
for years, as a result of which there's (still) a tremendous amount
of confusion on the net about what is the syntactic precedence in
FROM clauses.

			regards, tom lane






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux