开发者

I would like to make a field part of a many to many relationship

开发者 https://www.devze.com 2022-12-22 19:13 出处:网络
I have the following table called stores idstorezip 1Market 101569 2Market 201551 3Market 310468 4Market 410435

I have the following table called stores

   id     store       zip
   1     Market 1    01569
   2     Market 2    01551
   3     Market 3    10468
   4     Market 4    10435

Zip code table

   INSERT INTO `zip_codes` (`restaurants_locations_id`, `zip`, `state`, `latitude`, `longitude`, `city`, `full_state`) VALUES
(1, '06001', 'CT', ' 41.789698', ' -72.86431', 'Avon', 'Connecticut'),
(2, '06002', 'CT', ' 41.832798', ' -72.72642', 'Bloomfield', 'Connecticut'),
(3, '06010', 'CT', ' 41.682249', ' -72.93365', 'Bristol', 'Connecticut'),
(4, '06013', 'CT', ' 41.758415', ' -72.94642', 'Burlington', 'Connecticut'),
(5, '06016', 'CT', ' 41.909097', ' -72.54393', 'Wind开发者_高级运维sorville', 'Connecticut'),
(6, '06018', 'CT', ' 42.023510', ' -73.31103', 'Canaan', 'Connecticut'),
(7, '06019', 'CT', ' 41.834247', ' -72.89174', 'Canton', 'Connecticut'),

etc....

what I want is to create a table which will connect the zip field in the stores tables where one store will be found in several zicodes...

How would that table would look like?

Thanks


Create a table called Store_To_Zip_Map or whatever you want to call it.

This table only needs 2 columns: store_id and zip

Simply make a row in that table for each Store ID and Zip pairing. In the example below, stores 1 and 2 each have 2 zip codes. One of the zip codes is attached to both stores.

store_id    zip
1           11111
1           12222
2           12222
2           22222
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号