« Return to Thread: Zend_Select and the USING join keyword

Re: Zend_Select and the USING join keyword

by Daniel Rossi-2 :: Rate this Message:

Reply to Author | View in Thread

Bill Karwin wrote:

> I think I see where you're going with this.  I assume you are currently
> doing this:
>
> $select = $db->select()
>   ->from('table1')
>   ->join('table2', 'table1.column1 = table2.column1');
>
> And you're prefer to do this:
>
> $select = $db->select()
>   ->from('table1')
>   ->joinUsing('table2', 'column1');
>
> The two queries should produce the same result, assuming that your join
> condition in the first example is an equality between two columns that
> have the same name in both tables.  Let's open a feature request for
> this:  http://framework.zend.com/issues/browse/ZF-1845
>  
Something like that yes. I generally have the join columns the same
name, and then set foreign keys to them aswell. It would be nice if they
were picked up automatically.

> Also, you might like to use joinNatural(), which would be even more
> concise.  It is like USING, but automatically makes an equi-join using
> all columns that have the same name in both tables.  Here's how you do
> it in Zend_Db_Select:
>
> $select = $db->select()
>   ->from('table1')
>   ->joinNatural('table2');
>
> Both USING and NATURAL JOIN syntax forms are ANSI SQL standard, but do
> all our supported database brands support these forms?
>  
Interesting. Yes I was also looking at this. Ive never used this keyword
at all. usually INNER so it collects the least ammount of rows. Is it
the same pretty much, but just automatically detects the join columns ?

Im assuming like foreign keys the join columns need to be the same type.

 « Return to Thread: Zend_Select and the USING join keyword