[Zope] Duplicate column name in ZSQL Method

Tres Seaver tseaver@palladion.com
Tue, 15 Feb 2000 22:26:55 -0600


Martin Fahlgren <martin.fahlgren@salomon.at> wrote:

> Hello!
> 
> Is there any possibility to make a query like
> 
> select * from table1, table2
> 
> without explicitly typing every column name. If table1 and table2 have
> columns with the same names Zope raises an exception with the message
> "Duplicate column names"

Two problems:

 * The "duplicate column names" one can be solved by aliasing the table
   names::

     select t1.*, t2.* from table1 t1, table2 t2

   The syntax for doing this varies; you may need to add an 'as' or wrap the
   alias in quotes.

 * Without specifying a join condition, this query produceds a "Cartesian
   explosion": if table1 and table2 each have 100 records, the result set
   will have 10,000 records.  To avoid this, join the two tables using the
   common fields::

     select t1.*, t2.* from table1 t1, table2 t2
       where t2.foreign_key = t1.primary_key

-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com