pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: tjennette@thomasnelson.com
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL Joins
Date: Mon, 14 Jan 2002 17:01:55 -0500
Message-ID: <19527.1011045715@sss.pgh.pa.us> (raw)
In-Reply-To: <56893385.0201081316.25272d8c@posting.google.com>
References: <56893385.0201081316.25272d8c@posting.google.com>

tjennette@thomasnelson.com (Trace) writes:
> Can someone please tell me what this previously-written SQL is doing? 
> I don't understand how it is structured.

Apparently whoever wrote this doesn't believe in parentheses.  I'd think
it a lot more readable with parentheses and appropriate indentation,
viz:

FROM
  (  (eStoreManager.estore_dept_prod LEFT OUTER JOIN eStoreManager.estore_product
      ON eStoreManager.estore_dept_prod.sku = eStoreManager.estore_product.sku)
   RIGHT OUTER JOIN
     (eStoreManager.tblCProductClass LEFT OUTER JOIN eStoreManager.tblCProductClassProduct
      ON eStoreManager.tblCProductClass.ProductClassID = eStoreManager.tblCProductClassProduct.ProductClassID)
   ON eStoreManager.estore_product.sku = eStoreManager.tblCProductClassProduct.sku)
FULL OUTER JOIN
  (eStoreManager.tblCProductClassCreator INNER JOIN eStoreManager.tblCCreator
   ON eStoreManager.tblCProductClassCreator.CreatorID = eStoreManager.tblCCreator.CreatorID)
ON eStoreManager.tblCProductClass.ProductClassID = eStoreManager.tblCProductClassCreator.ProductClassID

BTW, since Postgres doesn't have schemas you'd need to lose the
"eStoreManager." prefixes, which aren't doing anything for readability
here either:

FROM
  (  (estore_dept_prod LEFT OUTER JOIN estore_product
      ON estore_dept_prod.sku = estore_product.sku)
   RIGHT OUTER JOIN
     (tblCProductClass LEFT OUTER JOIN tblCProductClassProduct
      ON tblCProductClass.ProductClassID = tblCProductClassProduct.ProductClassID)
   ON estore_product.sku = tblCProductClassProduct.sku)
FULL OUTER JOIN
  (tblCProductClassCreator INNER JOIN tblCCreator
   ON tblCProductClassCreator.CreatorID = tblCCreator.CreatorID)
ON tblCProductClass.ProductClassID = tblCProductClassCreator.ProductClassID

Does that help any?

If you're wondering how I knew where to put the parentheses, it's
because there's no place else they could go and still have a
syntactically valid statement.  So I suppose the author felt they
were unnecessary.  But I think it's more readable with 'em.

			regards, tom lane



view thread (3+ messages)

Message-ID: <19527.1011045715@sss.pgh.pa.us>
Permalink:  ../19527.1011045715@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19527.1011045715@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tjennette@thomasnelson.com
  Subject: Re: SQL Joins
  In-Reply-To: <19527.1011045715@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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