* Andrew 
> I am going to add another table to my lovely MySQL DB.
> 
> Basically it is the city table I need to add to.  For each city I 
> am going to
> have Towns.  So I need to relate many Towns to one CityID
> 
> The city table at the moment is:
> 
> City CityID
> 
> What the best way forward?

Create a Towns table, and link it to the Cities table?

CREATE TABLE Towns (
  TownID int unsigned not null auto_increment primary key,
  CityID int unsigned not null,
  Town varchar(40) not null,
  index (CityID),  
  index (Town(8)));

Show all towns for a city:

SELECT Town 
  FROM Towns
  NATURAL JOIN Cities
  WHERE Cities.City = "London";

or

SELECT T.Town 
  FROM Towns T
  LEFT JOIN Cities C ON
    C.CityID = T.CityID
  WHERE C.City = "London";

HTH,

-- 
Roger

---------------------------------------------------------------------
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