Thread: Need help with INNER Join

Need help with INNER Join

From
"Mag Gam"
Date:
Hello
 
When I needed to join tables I always used the equal syntax (ie. SELECT id from foo,fee where id.foo=id.fee)
 
To my understanding, it is preferred to use the INNER JOIN keyword. I am able to INNER JOIN 2 tables, but I am not sure of the syntax for 3 or more tables. Can someone please show me an example for that ?
 
TIA
 

Re: Need help with INNER Join

From
Frank Bax
Date:
Mag Gam wrote:
> When I needed to join tables I always used the equal syntax (ie. SELECT
> id from foo,fee where id.foo=id.fee)
>
> To my understanding, it is preferred to use the INNER JOIN keyword. I am
> able to INNER JOIN 2 tables, but I am not sure of the syntax for 3 or
> more tables. Can someone please show me an example for that ?


Your example will not work; you should have written:

SELECT foo.id from foo,fee where foo.id=fee.id

With inner join, this would be

SELECT foo.id FROM foo
INNER JOIN fee on foo.id=fee.id

Joining a third table would look like

SELECT foo.id FROM foo
INNER JOIN fee ON foo.id=fee.id
INNER JOIN bar ON bar.id=foo.id



Re: Need help with INNER Join

From
Emil Obermayr
Date:
Am Sonntag, 4. Mai 2008 schrieb Mag Gam:

> To my understanding, it is preferred to use the INNER JOIN keyword. I am
> able to INNER JOIN 2 tables, but I am not sure of the syntax for 3 or more
> tables. Can someone please show me an example for that ?

Just concatenate the joins, modern servers do not need hints by brackets and
such:

select * from a join b on a.id=b.aid join c on b.id=c.bid ;

In that respect, also take a look on "join using" and "natural join".

Re: Need help with INNER Join

From
"Mag Gam"
Date:
All,

thanks for the help. I will try this.

TIA


On Sun, May 4, 2008 at 10:52 AM, Frank Bax <fbax@sympatico.ca> wrote:
Mag Gam wrote:
When I needed to join tables I always used the equal syntax (ie. SELECT id from foo,fee where id.foo=id.fee)
 To my understanding, it is preferred to use the INNER JOIN keyword. I am able to INNER JOIN 2 tables, but I am not sure of the syntax for 3 or more tables. Can someone please show me an example for that ?


Your example will not work; you should have written:

SELECT foo.id from foo,fee where foo.id=fee.id

With inner join, this would be

SELECT foo.id FROM foo
INNER JOIN fee on foo.id=fee.id

Joining a third table would look like

SELECT foo.id FROM foo
INNER JOIN fee ON foo.id=fee.id
INNER JOIN bar ON bar.id=foo.id




--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice