pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
nested inner join help
5+ messages / 3 participants
[nested] [flat]

* nested inner join help
@ 2002-01-07 05:37  Darryl M. Wolski <drwolski@sympatico.ca>
  0 siblings, 2 replies; 5+ messages in thread

From: Darryl M. Wolski @ 2002-01-07 05:37 UTC (permalink / raw)
  To: pgsql-sql

I  have a query which works perfectly fine in mysql but won't
work in the same database in postgres...

Can anyone take a look at this and tell me what the problem is?

I get a parser error at (.

SELECT orderlines.quantity, products.productname, products.productcost, customers.custlname,customers.custfname
FROM (((orders INNER JOIN orderlines ON orders.orderid = orderlines.lnkorderid)  INNER JOIN customers ON (customers.custid = orders.lnkcustid)) INNER JOIN products ON (products.productid = orderlines.lnkproductid))
WHERE (((orders.orderid)=2));

It seems as soon as I try to nest an INNER JOIN I get these parser errors. I have tried this query a few different ways, and still cant get it to work.

Thank you so much!!

Darryl Wolski

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: nested inner join help
@ 2002-01-14 21:30  Josh Berkus <josh@agliodbs.com>
  parent: Darryl M. Wolski <drwolski@sympatico.ca>
  1 sibling, 1 reply; 5+ messages in thread

From: Josh Berkus @ 2002-01-14 21:30 UTC (permalink / raw)
  To: Darryl M. Wolski <drwolski@sympatico.ca>; pgsql-sql

Darryl,

In Postgres, neither the parentheses nor the word "INNER" are required.  You
 will significantly simplify your life if you get rid of them, and clean up
 your presentation of SQL text in order to debug your own joins.

One significant MSAccess <==> Postgres conflict is that Postgres assumes that
 parens in the FROM clause represent subselects (I think), while MS Access uses
 parens to organize JOINs.  Postgres behavior is, of course, more SQL92
 correct.

SELECT orderlines.quantity, products.productname, products.productcost,
 customers.custlname,customers.custfname
FROM orders JOIN orderlines ON orders.orderid = orderlines.lnkorderid 
   JOIN customers ON customers.custid = orders.lnkcustid 
   JOIN products ON products.productid = orderlines.lnkproductid
WHERE orders.orderid=2;

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: nested inner join help
@ 2002-01-14 21:37  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Darryl M. Wolski <drwolski@sympatico.ca>
  1 sibling, 0 replies; 5+ messages in thread

From: Tom Lane @ 2002-01-14 21:37 UTC (permalink / raw)
  To: Darryl M. Wolski <drwolski@sympatico.ca>; +Cc: pgsql-sql

"Darryl M. Wolski" <drwolski@sympatico.ca> writes:
> Can anyone take a look at this and tell me what the problem is?

> I get a parser error at (.

> SELECT orderlines.quantity, products.productname, products.productcost, cus=
> tomers.custlname,customers.custfname
> FROM (((orders INNER JOIN orderlines ON orders.orderid =3D orderlines.lnkor=
> derid)  INNER JOIN customers ON (customers.custid =3D orders.lnkcustid)) IN=
> NER JOIN products ON (products.productid =3D orderlines.lnkproductid))
> WHERE (((orders.orderid)=3D2));

Looks fine to me.  Are you using an old Postgres version?  We didn't
support JOIN keywords until 7.1.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: nested inner join help
@ 2002-01-14 23:25  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Josh Berkus <josh@agliodbs.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2002-01-14 23:25 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: Darryl M. Wolski <drwolski@sympatico.ca>; pgsql-sql

"Josh Berkus" <josh@agliodbs.com> writes:
> One significant MSAccess <==> Postgres conflict is that Postgres assumes that
>  parens in the FROM clause represent subselects (I think),

Huh?  Parenthesizing JOINs is perfectly valid, and I think it's good
style too in complex cases.  See the nearby "SQL Joins" thread for
an example of a query that's quite unreadable without 'em.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: nested inner join help
@ 2002-01-15 01:01  Josh Berkus <josh@agliodbs.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Josh Berkus @ 2002-01-15 01:01 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Josh Berkus <josh@agliodbs.com>; +Cc: Darryl M. Wolski <drwolski@sympatico.ca>; pgsql-sql

Tom,

> Huh?  Parenthesizing JOINs is perfectly valid, and I think it's good
> style too in complex cases.  See the nearby "SQL Joins" thread for
> an example of a query that's quite unreadable without 'em.

Aha.  I see.  Of course, the OUTER JOINs here sort of require parens.

So, Darryl, you do want to use parens some of time.  Just to make it harder for
 you to decide.  However, I would assert that in your example query they are
 not necessary and actually make the syntax more difficult.

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2002-01-15 01:01 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-07 05:37 nested inner join help Darryl M. Wolski <drwolski@sympatico.ca>
2002-01-14 21:30 ` Josh Berkus <josh@agliodbs.com>
2002-01-14 23:25   ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-15 01:01     ` Josh Berkus <josh@agliodbs.com>
2002-01-14 21:37 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox