From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: FROM + JOIN when more than one table in FROM |
Date: | 2008-03-13 14:33:21 |
Message-ID: | 20080313143321.GW1653@frubble.xen.chris-lamb.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Mar 12, 2008 at 12:48:22PM +0100, Ivan Sergio Borgonovo wrote:
> On Wed, 12 Mar 2008 11:48:24 +0100 Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> > Perhaps this would owrk:
>
> > FROM sm inner join st inner join pt inner join pm
>
> one of the inner join doesn't have an on relationship.
In general that doesn't really matter! For example these queries all
return the same results:
SELECT * FROM a, b WHERE a.n = b.n;
SELECT * FROM a INNER JOIN b ON a.n = b.n;
SELECT * FROM a CROSS JOIN b WHERE a.n = b.n;
SELECT * FROM a INNER JOIN b ON TRUE WHERE a.n = b.n;
In your case there are probably a couple of reasonable choices. Because
they're all just inner joins, I'd use the old fashioned cross syntax:
SELECT *
FROM pay p, ship s, paytypes pt, shiptypes st
WHERE p.typeid = pt.typeid
AND s.typeid = st.typeid
AND p.methodid = 1
AND s.methodid = 1;
If you want to use JOIN syntax, you could do something like:
SELECT *
FROM
pay p INNER JOIN paytypes pt ON p.typeid = pt.typeid,
ship s INNER JOIN shiptypes st ON s.typeid = st.typeid
WHERE p.methodid = 1
AND s.methodid = 1;
Or you could do something completely different!
Sam
From | Date | Subject | |
---|---|---|---|
Next Message | Hans Schou | 2008-03-13 14:49:37 | Percent-encoding conversion to binary, %C2%A9 = © |
Previous Message | Nikola | 2008-03-13 14:27:02 | WAL Archiving Error |