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?
mcpilot1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Can you post an ER-digram?
Julian HansenCommented:
"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.
mcpilot1Author Commented:
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?
ste5anSenior DeveloperCommented:
Sounds like a normal Parent-Child hierarchy (1:m). Thus a Distributor column in the User table should be sufficient.
Julian HansenCommented:
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".
Exactly, this is the scenario #1 I referred to above.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.