Skip site navigation (1) Skip section navigation (2)

Inner Join question

From: "Keith Turner" <kturner(at)cloudsystems(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Inner Join question
Date: 2008-11-07 21:38:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Should have used reply all - solution works and appreciated and now
posted to group.



Can't do the devices.*, rooms.*, bridge.* as I get the error "column ID
is duplicated" - but explicitly naming the columns and using AS on these
is no big deal

The join worked, which is what I'm really thankful for - wasn't sure
about the syntax of adding a join to a join in that way - that's why
it's a novice list.

Much appreciated,


-----Original Message-----
From: Michael Swierczek [mailto:mike(dot)swierczek(at)gmail(dot)com] 
Sent: Friday, November 07, 2008 3:23 PM
To: Keith Turner
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] Inner Join question

    The * was a problem because the query analyzer did not know which
table to grab all columns from.   If you want all columns from more
than one table, you have to do alias.* for each one.   In this case,
you want:
select devices.*, rooms.*, bridge.* from ....

If you want devices to always be listed, even with no bridge entries,
you would do a left join to guarantee all rows from the first table
are included.

I think this is what you want:
SELECT devices.*, rooms.*, bridge.*
FROM devices
LEFT JOIN bridge on
LEFT JOIN room on bridge.roomid =;


On Fri, Nov 7, 2008 at 3:45 PM, Keith Turner <kturner(at)cloudsystems(dot)com>
> Hi,
> I have three tables
> 1) A list of devices
> 2) List of rooms
> 3) A bridge table that relates the two using each table's ID column
> Any device can be in 0 to All rooms
> I want to create a view that joins both tables that in includes all
> columns from all 3 tables.
> I'm not sure how to link joins in the Postgres SQL syntax. I'm more
> to the =* one.
> I want to do something like
> SELECT (explicit list of all tables columns - didn't like * but was ok
> with actual list)
> devices,rooms,bridge
> bridgeroomid =
> bridgedeviceid=*
> so that devices with no associated rooms would have null values for
> those columns but be listed.
> Any advice appreciated.
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:

pgsql-novice by date

Next:From: gcjDate: 2008-11-11 15:23:38
Subject: Automating Postgres Backup
Previous:From: Michael SwierczekDate: 2008-11-07 21:23:23
Subject: Re: Inner Join question

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group