NYCPHP Meetup

NYPHP.org

[nycphp-talk] naming identifiers

Michael Southwell michael.southwell at nyphp.com
Mon Aug 31 23:33:26 EDT 2009


Daniel Convissor wrote:
> PHP code.  Most importantly, if you name everything "id," then you have 
> to explicitly spell out your JOIN statements in an ON clause
> 
> SELECT product_name, vendor_name
> FROM product
> JOIN vendor ON (vendor.id = product.vendor_id)
> 
> When it's so much easier to take advantage of USING clause:
> 
> SELECT product_name, vendor_name
> FROM product
> JOIN vendor USING (vendor_id)

It's always seemed easier and clearer to me to use WHERE instead of JOIN 
(where the table IDs are indeed named id, and the foreign keys are 
labeled with the table name):

SELECT product_name, vendor_name
FROM product, vendor
WHERE vendor.id = product.vendor_id

but maybe that's just my ignorance


-- 
=================
Michael Southwell
Vice President, Education
NYPHP TRAINING:  http://nyphp.com/Training/Indepth



More information about the talk mailing list