List:General Discussion« Previous MessageNext Message »
From:Benjamin Pflugmann Date:May 21 1999 4:25am
Subject:Re: Joining tables
View as plain text  
Hi.

On Wed, May 19, 1999 at 10:06:45AM -0500, peter@stripped wrote:
> On 18 May 99, at 18:11, Jim Faucette wrote:
> 
> > Table A:
> > num INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT;
> > lname CHAR(20) NOT NULL;
> > fname CHAR(20) NOT NULL;
> > KEY n (lname, fname);
> > 
> > Table B:
> > num INT UNSIGNED NOT NULL;
> > phone char(20);
> > 
> > Then to get all of John Smith's phone numbers you'd:
> > SELECT fname, lname, phone FROM A, B
> > WHERE lname ='Smith' AND fname='John' AND A.num = B.num;

This results in a list of the phone numbers of John Smith.

> Why not just do this
> 
>  SELECT fname, lname, phone FROM A, B
>  WHERE A.num = B.num;

This results in a list of phone numbers of all people listed in table A.

> I don't see the need for the lname and fname.

They select of whom you want to see the phone number.

Bye,

	Benjamin.

-- 
Benjamin Pflugmann aka Philemon                       philemon@stripped
Programming, Guestbook support                voice: +49 941 94 65 939
SPiN GmbH             http://www.spin.de        fax: +49 941 94 65 938
======= Web design - Java chats - Guestbooks - Java/CGI coding =======

Attachment: [application/pgp-signature]
Thread
Joining tablesDan Parisien19 May
  • Re: Joining tablesThimble Smith19 May
  • Re: Joining tablesJim Faucette19 May
    • Re: Joining tablespeter19 May
      • Re: Joining tablesBenjamin Pflugmann21 May