From drwolski@sympatico.ca Mon Jan 7 05:38:02 2002 Received: from tomts20-srv.bellnexxia.net (tomts20.bellnexxia.net [209.226.175.74]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g075c1m83936 for ; Mon, 7 Jan 2002 00:38:02 -0500 (EST) (envelope-from drwolski@sympatico.ca) Received: from arbour ([64.229.28.239]) by tomts20-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with SMTP id <20020107053802.YBVO9253.tomts20-srv.bellnexxia.net@arbour> for ; Mon, 7 Jan 2002 00:38:02 -0500 Message-ID: <000801c1973d$75ea1980$ae00a8c0@arbour> From: "Darryl M. Wolski" To: Subject: nested inner join help Date: Mon, 7 Jan 2002 00:37:56 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0005_01C19713.8CAC27F0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Archive-Number: 200201/130 X-Sequence-Number: 6218 This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C19713.8CAC27F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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, 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)); 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 ------=_NextPart_000_0005_01C19713.8CAC27F0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I  have a query which works perfectly= fine in=20 mysql but won't
work in the same database in=20 postgres...
 
Can anyone take a look at this and tell me= what the=20 problem is?
 
I get a parser error at (.
 
SELECT orderlines.quantity, products.produ= ctname,=20 products.productcost, customers.custlname,customers.custfname
FROM (((or= ders=20 INNER JOIN orderlines ON orders.orderid =3D orderlines.lnkorderid)  IN= NER=20 JOIN customers ON (customers.custid =3D orders.lnkcustid)) INNER JOIN produ= cts ON=20 (products.productid =3D orderlines.lnkproductid))
WHERE=20 (((orders.orderid)=3D2));
It seems as soon as I try to nest an INNER= JOIN I=20 get these parser errors. I have tried this query a few different ways, and = still=20 cant get it to work.
 
Thank you so much!!
 
Darryl Wolski
------=_NextPart_000_0005_01C19713.8CAC27F0-- From josh@agliodbs.com Mon Jan 14 21:30:36 2002 Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0ELUaV03408 for ; Mon, 14 Jan 2002 16:30:36 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.2) with HTTP id 601184; Mon, 14 Jan 2002 13:30:36 -0800 From: "Josh Berkus" Subject: Re: nested inner join help To: "Darryl M. Wolski" , X-Mailer: CommuniGate Pro Web Mailer v.3.5.2 Date: Mon, 14 Jan 2002 13:30:36 -0800 Message-ID: In-Reply-To: <000801c1973d$75ea1980$ae00a8c0@arbour> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200201/145 X-Sequence-Number: 6233 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 From tgl@sss.pgh.pa.us Mon Jan 14 21:37:26 2002 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0ELbQV08173 for ; Mon, 14 Jan 2002 16:37:26 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g0ELbQg19357; Mon, 14 Jan 2002 16:37:27 -0500 (EST) To: "Darryl M. Wolski" cc: pgsql-sql@postgresql.org Subject: Re: nested inner join help In-reply-to: <000801c1973d$75ea1980$ae00a8c0@arbour> References: <000801c1973d$75ea1980$ae00a8c0@arbour> Comments: In-reply-to "Darryl M. Wolski" message dated "Mon, 07 Jan 2002 00:37:56 -0500" Date: Mon, 14 Jan 2002 16:37:26 -0500 Message-ID: <19354.1011044246@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200201/149 X-Sequence-Number: 6235 "Darryl M. Wolski" 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 From tgl@sss.pgh.pa.us Mon Jan 14 23:25:38 2002 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0ENPcV71449 for ; Mon, 14 Jan 2002 18:25:38 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g0ENPbg20147; Mon, 14 Jan 2002 18:25:37 -0500 (EST) To: "Josh Berkus" cc: "Darryl M. Wolski" , pgsql-sql@postgresql.org Subject: Re: nested inner join help In-reply-to: References: Comments: In-reply-to "Josh Berkus" message dated "Mon, 14 Jan 2002 13:30:36 -0800" Date: Mon, 14 Jan 2002 18:25:37 -0500 Message-ID: <20144.1011050737@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200201/153 X-Sequence-Number: 6239 "Josh Berkus" 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 From josh@agliodbs.com Tue Jan 15 01:01:40 2002 Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0F11dV02311 for ; Mon, 14 Jan 2002 20:01:40 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.2) with HTTP id 601476; Mon, 14 Jan 2002 17:01:40 -0800 From: "Josh Berkus" Subject: Re: nested inner join help To: Tom Lane , "Josh Berkus" Cc: "Darryl M. Wolski" , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.2 Date: Mon, 14 Jan 2002 17:01:40 -0800 Message-ID: In-Reply-To: <20144.1011050737@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200201/155 X-Sequence-Number: 6241 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