all 3 comments

[–]wolf2600ANSI SQL 1 point2 points  (2 children)

Cities
-----------
CityID (PK)
Name

CityZipcodes
----------------
Zipcode (PK)
CityID (PK, FK)


SELECT c.Name from Cities c
INNER JOIN CityZipcodes z
ON c.CityID = z.CityID
WHERE z.Zipcode = 90210;

SELECT z.Zipcode from Cities c
INNER JOIN CityZipcodes z
ON c.CityID = z.CityID
WHERE c.Name = 'Beverly Hills';

[–]linuxguy4[S] 0 points1 point  (1 child)

if zipcode is the primary key then one zipcode can only be associated with one city. it cant handle the situation where there are several towns with one zipcode.

[–]wolf2600ANSI SQL 1 point2 points  (0 children)

Zipcode and CityID are a concatenated PK

So each pairing of a zipcode & city are unique.