yes, for example with select():

s1 = select([t.c.c1, t.c.c2, t.c.c3])

s2 = select([t2.c.c1, t.c.c2, null().label('col4'), null.label('col5')])

u1 = union(s1, s2)


I'd recommend using union() and select() to create these queries. the ORM 
Query.union() method is not as easy to use and long term the above technique 
with union() and select() will be how it's done.




On Tue, Jun 2, 2020, at 2:09 PM, Justvuur wrote:
> Hi All,
> 
> I would like to do a union between 3 or 4 tables using the all powerful 
> sqlalchemy. The tables have about 3 columns that are the same but each table 
> has 2 different columns.
> 
> Is it possible to do a query as below in sqlalchemy?
> 
> Select Col1, Col2, Col3, Col4, Col5 from Table1
> Union
> Select Col1, Col2, Col3, Null as Col4, Null as Col5 from Table2
> 
> 
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/a74e30bb-b7b3-4120-accf-68dac445ac51%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/a74e30bb-b7b3-4120-accf-68dac445ac51%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3b690f95-5e9c-4a79-8a86-fea460705bd5%40www.fastmail.com.

Reply via email to