Re: Query having issues... - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Query having issues...
Date
Msg-id Pine.LNX.4.44.0209131052030.2059-100000@cm-lcon1-46-187.cm.vtr.net
Whole thread Raw
In response to Query having issues...  (Chris Bowlby <excalibur@hub.org>)
List pgsql-general
Chris Bowlby dijo:

>      SELECT co.first_name, co.last_name, co.email_address,
>             a.password, c.company_number
>      FROM contact co, domain d
>      LEFT JOIN account_info a ON (co.contact_id = a.contact_id)
>      LEFT JOIN company c ON (co.company_id = c.company_id)
>      WHERE d.domain_id = '666'
>      AND d.company_id = co.company_id;

Note that you are JOINing "domain d" with "account_info a"; by the time
this is looked up, there is no relation co there, so the qualification
doesn't make sense.  Try this:

      SELECT co.first_name, co.last_name, co.email_address,
             a.password, c.company_number
      FROM domain d, contact co
      LEFT JOIN account_info a ON (co.contact_id = a.contact_id)
      LEFT JOIN company c ON (co.company_id = c.company_id)
      WHERE d.domain_id = '666'
      AND d.company_id = co.company_id;

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"Now I have my system running, not a byte was off the shelf;
It rarely breaks and when it does I fix the code myself.
It's stable, clean and elegant, and lightning fast as well,
And it doesn't cost a nickel, so Bill Gates can go to hell."


pgsql-general by date:

Previous
From: "Carmen Wai"
Date:
Subject: Size of database
Next
From: pkubat@spamcop.net
Date:
Subject: Case (in)-sensitivity & preserving case