Answer the question
In order to leave comments, you need to log in
How to query a one-to-many dependency, at the lowest cost, in MySQL?
Hello, I have an array with 100 elements. Let's say it's cities. Each user can subscribe to several cities and receive information on them. At one time unit, the subscription check for all users begins. Also, users can request this information themselves, several requests can be performed in one unit of time. The list of cities in the array can change, the check is carried out only on this array.
I did this, iterate over the array and see if there is a subscription and the user who requested it. Resources ran out very quickly.
How can this task be accomplished? It is possible to apply some other technologies ...
Answer the question
In order to leave comments, you need to log in
What you've actually described is a many-to-many relationship.
One user can be associated with several cities, and several users can be associated with one city.
You need to implement a similar structure in the database
And then you need competent indexes on tables.
In the relationship table, make the primary key a composite of 2 fields
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question