NYCPHP Meetup

NYPHP.org

[nycphp-talk] What's the best way query a table with a "one-to-many"relationship? Suggestions???

inforequest sm11szw02 at sneakemail.com
Mon Jul 5 08:26:39 EDT 2004


Gabriel PREDA radical-at-amr.ro |nyphp 04/2004| wrote:

>   This can only be acomplished with 2 queryes... Because of the result...
>    Let's say that "x" are results from products and "y" are from photos...
>you would have something like:
>xxxx yyyy
>        yyyy
>        yyyy
>
>    This result set is imposible to be represented by an SQL server... the
>closest match you can get is
>xxxx     yyyy
>NULLs yyyy
>NULLs yyyy
>    But this would make things worse because you would have to skip many
>NULLs...
>
>Have a good time programming !
>  
>
>>Alan
>>    
>>
>Gabriel
>

While I recommend the approach described above, I add that it is 
possible to accompish the end result without two queries, using 
practical techniques that are not pure database methods. It is also 
possible that a non-normalized database schema would serve the 
application well, with a minial impact on scalabaility up to some 
practical limit.

However, given the potential for mis-use, I agree these are best 
reserved for the experienced programmer, or for deployment of an 
"optimized" application after development is completed. Unless one 
understands the impact of a shortcut, taking tha shortcut involves risk 
(and is not generally recommended).

-=john




More information about the talk mailing list