mysql - Issues setting up a N-M relationship -
Using MySQL, I try to install multiple relationships from 1 by using already uploaded data in the database I am doing For example, say I have a list of names in a table and I want to add them to the lists of places that they are, obviously 1 person can go to many different places, but let me set up this set up There is a problem taking place.
----- Name ----------- ID --------- John Smith 1 Random 2 Seth Boy 3 ---- --------------------------
I have another table which will look like this:
------- City --------- ID --- ------ New York 1 Chicago 2 Orlando 3 La 4 ------- ------------------------
I am looking for something like this:
-------- name -------- city ---------- John Smith Chicago John Smith Orlando John Smith New York Seth Guy Chicago who randomized LA - ----------------------------- ------
I know That John Smith has been in all three places because the original file I upload tells me so much, but I want the database to make that connection and accordingly accordingly keep it accordingly. As described in the observations, it is an N-M relationship, not a 1-N relationship, it
You need an additional "mapping" table to record visits:
create table visits (person Iid INT, city_id INT, contract visits_pack primary key (person_id, city_id)); After that, you can query all visits with something added: select the person. Name, city People by name add visits to the person. ID = Visits Visit on PRSN_ID city. City_ID = city.id
Comments
Post a Comment