This: t=db.color.with_alias('t') c=db.color.with_alias('c') accessible_works=db().select(db.work.ALL, db.t.html_code, db.c.html_code, left=[db.t.on(db.t.id==db.work.title_color), db.c.on(db.c.id==db.work.cover_color)])
Should be this: t=db.color.with_alias('t') c=db.color.with_alias('c') accessible_works=db().select(db.work.ALL, t.html_code, c.html_code, left=[t.on(t.id==db.work.title_color), c.on(c.id==db.work.cover_color)]) On Oct 12, 10:48 pm, Audra Rudys <sphin...@gmail.com> wrote: > Please help! I'm trying to join using the same table twice, thus I need to > do an alias. This is the first time I've ever tried an alias, so I don't > know if I'm doing this right. > > If I were writing SQL code, I would write something like the following: > SELECT db.work.*, db.tcolor.html_code, db.ccolor.html_code > FROM db.work LEFT OUTER JOIN color as tcolor ON db.work.title_color == > tcolor.id > LEFT OUTER JOIN color as ccolor ON db.work.cover_color == ccolor.id > > This is what I'm trying, but it's yielding an error: OperationalError: > ambiguous > column name: color.html_code > > def view(): > t=db.color.with_alias('t') > c=db.color.with_alias('c') > accessible_works=db().select(db.work.ALL, db.t.html_code, db.c.html_code, > left=[db.t.on(db.t.id==db.work.title_color), > db.c.on(db.c.id==db.work.cover_color)]) > return dict(works=accessible_works) > > *I'm seeing the following in the variables: *('SELECT work.id, > work.title, work.title_font, wor...lor LEFT JOIN color ON > color.id=work.cover_color;',) > > *What am I doing wrong? (In case it's useful, I'm running on a PC > *from source code, version 1.87.2, downloaded this morning.) > > Thanks for your help, > > Audra