Re: getting from one table listing from another

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 12:56 PM -0500 8/19/07, Larry Garfield wrote:
On Sunday 19 August 2007, tedd wrote:
 > Wouldn't this be simpler?

 SELECT a.name, b.points
 FROM table_name a, table_name_points b
 > WHERE a.name = b.name


There are various kinds of JOINs.  The most common you'll actually use are
INNER JOIN and LEFT OUTER JOIN.
You should use an explicit INNER JOIN over an implicit join (what you have
above) for two main reasons:

1) It's clearer and more obvious what you're doing.
2) The syntax for implicit joins changed very slightly in MySQL 5, so code
using them *may* in some circumstances, break when you upgrade.  (We
discovered this the hard way at work when dealing with some legacy code.)
3) I believe it's more cross-database standardized (nobody expects the Spanish
Inquisition!)

INNER JOINs return rows only if there are matching values in both tables. LEFT OUTER JOINs return rows if there are matches in just the first (left)
table, and fill in NULL values for the columns from the right table if
nothing matches.

Larry:

Ok, that makes sense. The term "JOIN" means to consider/include the contents from more than one table. The "INNER" term is for items that are common between the tables (i.e., intersection) and the "OUTER" term is to consider the items of one table regardless of their presence in another.

However, the LEFT and RIGHT will take me a while to figure out.

Thanks, for your explanation.

tedd


--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux