"Jeff Lewis" <[EMAIL PROTECTED]> wrote:
> I fought the urge to post this here but have to :(
> owners
> -ownerID
> -teamname
> -more fields
> teampages
> -ownerID
> -bio
> Anyway, I'm doing a select on the database like this: select ownerID,
> last_update FROM teampages ORDER BY last_update DESC LIMIT 10
> The thing is, I want to get the team name from the other table as well.
> anyone help me out?

I've read the other solutions, they all used STRAIGHT JOINs.  You may want
to consider a LEFT JOIN (form of an OUTER JOIN).  A LEFT JOIN will return
all the records from table A and those from table B that match the records
from table A.  The implication is that with a straight join if there is no
record for an ownerID corresponding to the record from the table teampages
then the record from teampages won't be returned.  So if a teamname never
got entered in owners or the ID was mis-entered your query would not return
all of the records from teampages and you probably want it to.  Using a LEFT
JOIN the record from teampages will be returned, but since there's no
corresponding record in table owners the field teamname will be blank.
Assuming all of the data is in both tables it's not a problem, but believe
me at some point when doing database programming this issue will arise.

SELECT teampages.ownerID, teampages.last_update, owners.teamname
FROM teampages
LEFT JOIN owners
ON teampages.ownerID = owners.ownerID
ORDER BY last_update

Steve Werby
President, Befriend Internet Services LLC

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to