Re: [SQL] Need help with a special JOIN

2012-09-29 Thread Johnny Winn
On Sat, Sep 29, 2012 at 2:28 PM, Victor Sterpu wrote: > This is a way to do it, but things will change if you have many > attributes/object > > SELECT o.*, COALESCE(a1.value, a2.value) > FROM objects AS o > LEFT JOIN attributes AS a1 ON (a1.object_id = o.id) > LEFT JOIN attributes AS a2 ON (a2.ob

Re: [SQL] Need help with a special JOIN

2012-09-29 Thread Victor Sterpu
This is a way to do it, but things will change if you have many attributes/object SELECT o.*, COALESCE(a1.value, a2.value) FROM objects AS o LEFT JOIN attributes AS a1 ON (a1.object_id = o.id) LEFT JOIN attributes AS a2 ON (a2.object_id = 0); On 29.09.2012 19:02, Andreas wrote: Hi, asume I've

Re: [SQL] Need help with a special JOIN

2012-09-29 Thread David Johnston
On Sep 29, 2012, at 12:02, Andreas wrote: > Hi, > > asume I've got 2 tables > > objects ( id int, name text ) > attributes ( object_id int, value int ) > > attributes has a default entry with object_id = 0 and some other where > another value should be used. > > e.g. > objects > ( 1, '

Re: [SQL] Need help with a special JOIN

2012-09-29 Thread Samuel Gendler
On Sat, Sep 29, 2012 at 9:02 AM, Andreas wrote: > Hi, > > asume I've got 2 tables > > objects ( id int, name text ) > attributes ( object_id int, value int ) > > attributes has a default entry with object_id = 0 and some other where > another value should be used. > > e.g. > objects > ( 1,

[SQL] Need help with a special JOIN

2012-09-29 Thread Andreas
Hi, asume I've got 2 tables objects ( id int, name text ) attributes ( object_id int, value int ) attributes has a default entry with object_id = 0 and some other where another value should be used. e.g. objects ( 1, 'A' ), ( 2, 'B' ), ( 3, 'C' ) attributes ( 0, 42