NYCPHP Meetup

NYPHP.org

[nycphp-talk] naming identifiers

Andy Dirnberger dirn at dirnonline.com
Tue Sep 1 09:41:11 EDT 2009


On Tue, Sep 1, 2009 at 8:58 AM, tedd <tedd at sperling.com> wrote:
>
> I need to understand joins much better than I do now because the first query I fully understand while the second I don't.
>

Think of the WHERE clause as the filter.  Use it to place restrictions
on what information is returned.

WHERE price > 50 AND color = 'red'

In the previous example you also had things like "vendor.id =
product.vendor_id."  You aren't using this to filter the data.  You
are using it to link up two tables.  This is where the JOIN clause
comes in.  For example, if you want a list of products with their
associated vendors:

FROM products
INNER JOIN vendors ON products.vendor_id = vendors.id -- or whatever
the fields are called

To also link to an optional promotion running for a product:

LEFT OUTER JOIN promotions ON products. promotion_id = promotions.id



More information about the talk mailing list