ill leave the full thing as an exercise, but the general format if  
you have "tablea" and "tableb" is like:

select([tablea.c.col1, tablea.c.col2, tableb.c.col1, tableb.c.col2],  
and_(tablea.c.col1=='foo', tableb.c.col2=='bar'), from_obj= 
[tablea.join(tableb, onclause=tablea.c.col3==tableb.c.col4)],  
order_by=[tablea.c.col3])

to actually get the aliases  in there, its more like:

tablea_alias = tablea.alias('ta')
tableb_alias = tableb.alias('tb')

select([tablea_alias.c.col1, tablea_alias.c.col2,  
tableb_alias.c.col1, tableb_alias.c.col2], and_ 
(tablea_alias.c.col1=='foo', tableb_alias.c.col2=='bar'), from_obj= 
[tablea_alias.join(tableb_alias,  
onclause=tablea_alias.c.col3==tableb_alias.c.col4)], order_by= 
[tablea_alias.c.col3])

to join many tables together is like:

tablea.join(tableb).join(tablec).outerjoin(tabled).join(tablee) ....

for "left outer join" use "outerjoin" instead of "join".

On Sep 5, 2006, at 12:25 PM, Valentin Kuznetsov wrote:

> Hi,
> I cannot find out how correctly to write in SQLAlchemy the following
> SQL statement:
>
>      select
>        f.logical_name,
>        f.filesize,
>        fs.name,
>        ft.name
>      from t_processed_dataset pd
>        join t_processing p
>          on p.primary_dataset = pd.primary_dataset
>          and p.name = pd.name
>        join t_block b
>          on b.processing = p.id
>        join t_block_status bs
>          on bs.id = b.status
>        left join t_file f
>          on f.inblock = b.id
>        left join t_file_status fs
>          on fs.id = f.status
>        left join t_file_type ft
>          on ft.id = f.type
>      where pd.id='%s' and b.id='%s'
>      order by f.logical_name
>
> I would appreciate your help.
> Valentin.
>
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to