thanks to all respondents! one more thing, i have 2 foreign keys in the 
bridge table, but not a primary key. is a primary key in the bridge 
necessary for this type of join to work? thanks again.

Begin forwarded message:

> From: Roger Karnouk <[EMAIL PROTECTED]>
> Date: Wed Jan 23, 2002  03:25:06 PM US/Pacific
> To: mike vogel <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> Subject: RE: three-way join
>
>
>
> create table magazine
> (Mag_id int primary key,
> Name char(30));
>
> create table customer
> (cust_id int primary key,
> name char(30));
>
> create table bridge
> (cust_id int not null,
> mag_id int not null,
> primary key(mag_id,cust_id));
>
> insert into customer values 
> (10,'John'),(24,'Luke'),(43,'Tony'),(25,'Matt');
>
> insert into magazine values (13,'carMag'),(25,'cosmo'),(9,'farmingMag');
>
> insert into bridge values (10,13),(10,9),(24,13),(42,9),(25,25);
>
> select c.name from magazine m inner join bridge b on (m.mag_id = 
> b.mag_id)
> inner join customer c on (c.cust_id = b.cust_id)
> where m.Name = 'carmag';
>
> -----Original Message-----
> From: mike vogel [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 23, 2002 5:51 PM
> To: [EMAIL PROTECTED]
> Subject: three-way join
>
>
> i  understand that creating a M:N relationship in mysql involves 3
> tables, one of which being a bridge, but how do i join the first and
> third tables by way of a bridge?
>
>   example: a table of subscribers and a table of magazines with a bridge
> in the middle. how do i select just the magazines fred is subscribed to?
> thanks in advance and sorry if this is a confusing question.
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to