In that case, it is safe to assume that each library can itself be a primary site. If we use NY City as an example, there would be:
- New York Central Libary (primary site)
- Manhattan Branch (secondary site)
- Brooklyn Branch (maybe also considered a secondary or tertiary)
etc.
If the Brooklyn Branch had no relationship with the New York Central Libary location, then the Brooklyn Branch could be considered a primary site. We don't know at this time. We're just concerned with making sure the database can accomodate, right?
I hope I'm following you so far.
Here are the tables:
COMANY
company_id,
company_name
SITES
company_id,
site_name,
ranking
Notice I included a column called "ranking" where you could enter an integer to give it a preference in the hierarchy.
So, using libraries as an example, maybe for the company_name, you could have something like "New York Public Library System" with a company_id of "10", okay?
We might consider the Manhattan Branch as the primary location, so would give that location a ranking of "1". Brooklyn Branch might be considered a secondary site so we give it "2".
If we wanted to list the primary and secondary locations of this company, then, the query would look like:
$sql = "SELECT c.company_name,
s.site_name
FROM COMPANY AS c
LEFT JOIN SITES AS s
ON (c.company_id = s.company_id)
WHERE c.company_id = '10'
ORDER BY s.ranking";
Hope that all made sense.