I am trying to create a group login mechanism whereby individual locations can log in and view their own information but also, the Head Office can log in and see all locations together.

My thoughts are: Add a new column called parent_id so the data would look like:

Code:
Customers:
id       parent_id          name
1        5                  location 1
2        5                  location 2
3        5                  location 3
4        5                  location 4
5        null               Head Office

Users:
id       customer_id       login
1        1                 email1@dot.com
2        2                 email2@dot.com
3        5                 email3@dot.com
When user 3 logs in, I am trying to ascertain the best way to identify it is a group login

I was thinking something like:

Code:
SELECT id, name
FROM Customers c
INNER JOIN Users u
ON c.id=u.customer_id
WHERE u.login = 'email3@dot.com'
-- I was thinking, if there was a way to count matching parent_id I could then identify any customers/users where the count(parent_id) > 0

i.e. something like this (no idea how it should be written):

Code:
SELECT id, name, count(parent_id WHERE parent_id = id)
FROM Customers c
INNER JOIN Users u
ON c.id=u.customer_id
WHERE u.login = 'email3@dot.com'
Is this possible? Or is there a much easier, more logical way to do this?

Thanks