Link to home
Start Free TrialLog in
Avatar of mcpilot1
mcpilot1

asked on

MYSQL Database - Association question

Friends - I am working on revmping a MySQL database set up by a predecessor and need to do the following

The database is a list of customers, basically. Some of those customers are "distributors" and others are "end users"

I need to be able to associate customers with distributors, meaning, one distributor might oversee 20 end users so I want to add a means of associating those 20 users with that one distributor.

Whomever set this SB up initially did, at least, set up a unique ID for each entry, "uniqueid". Is it reasonable to add a field to this DB called "associations" that then collects uniqueid's for each of the associated end users? So over time, "Dist ABC" would have, in the "associations" field, 1234 ,1324, 2873, 2339, etc that I can output later?

Or would it be more advantageous to have a completely different table that collects that information?
Avatar of ste5an
ste5an
Flag of Germany image

With out further information, this question is not determinable. What are your requirements?

Can you post an ER-digram?
"Dist ABC" would have, in the "associations" field, 1234 ,1324, 2873, 2339, etc that I can output later?
Not a great idea.
How you do this is dependent on how the data is used. For instance if a distributor uniquely overseas a particular customer (i.e once assigned that customer is bound to that distributor) or if multiple distributors can be linked to a client.

Scenario #1
Client records have a distributor_id field that is linked to the distributor table

Scenario #2
You create a separate Distributor_Client table that keeps the Distributor_id and Client_id for the association.

Without more information on your data setup and more importantly use - it is difficult to make a call.

However, having a field that stores all the associations in one field in most cases has only disadvantages.
Avatar of mcpilot1
mcpilot1

ASKER

Sorry for the vagueness.  In this case, only one distributor will oversee a list of end-users. There will not be a scenario where the end user is called by more than one distribtors.

In fact, the distributor will have rights to create his own set of end users. So, every time the distributor creates a user, that user is now "his", and the end user should be associated with this distributor. Later, the distributor should be able to log on to his account and review a full list of all of the and users under his umbrella.

I hope that helps - it sounds like what I may be able to do, then, is create a field in the existing table and every time a distributor create a new end user, it writes the distributor ID to that users' "association" field, then when the distributor logs in, I can call all end users "WHERE associationID is x".

Sound logical?
Sounds like a normal Parent-Child hierarchy (1:m). Thus a Distributor column in the User table should be sufficient.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial