Re: getting from one table listing from another

From: Date: Sun, 19 Aug 2007 19:02:31 +0000
Subject: Re: getting from one table listing from another
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-261022@lists.php.net to get a copy of this message
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

« previous php.general (#261022) next »