Hello Guys,
I'm guessing this what you would call an 'advanced' query, although with my knowledge as it is, most things seem pretty advanced lol.
I'm hoping you'll be able to help, I'll try and explain to the best of my abilities what i'm trying to achieve in the hope you'll be able to help. I've also copied in my current efforts (which are shocking) so you can see how poor i am with this kind of thing.
In my database I have the following tables.
member
tblUnits
tblUnitsOwners
tblGroups
Now the concept behind this is that I have a list of members (in the members table), each member is able to own many units, and a unit can be owned by many members. A unit can also be be put into a group, a group can store many units, but a unit may only belong to one group. A member may also own many other members, but a member can only be owned by one member.
So i've constructed the database as best I can, and i'm hoping it will meet my requirements, but if it doesn't then i'm more than happy to change things.
The 'member' table consists of three fields (ID, Name, Owner_id).
The 'tblUnits' table contains all the information on the units, fields are (ID, UnitName, GroupID)
The 'tblUnitsOwners' table contains link data between members and the units, fields are (ID, MemberID, UnitID)
The 'tblGroups' table contains information on the groups, fields are (ID, GroupName, GroupDescription)
Now the desired result is a list of units that are owned by particular user, such as user '1', that can be organised into thier 'groups' and with each box I want a list of other users that own that box, I've tried to illustrate this below.
Group 1 Title
-------------
Unit 1 - User 2
- User 4
- User 5
Unit 3 - User 2
Unit 4 - User 2
Unit 7 - User 5
- User 4
Group 2 Title
-------------
Unit 2 - User 4
Unit 5 - User 8
- User 9
Anyway, i'm mildy proficiant with ColdFusion so grouping the output isn't an issue, its just this query that has got me stumped, and i thought it a little heavy for the CF forum.
Below is a copy of what i've managed to cobble together so far, although i'm pretty convinced its next to useless.
You'll notice that the field names are a little different to the ones i've given above, but dont fuss to much, i'm looking for a more general solution as to how my JOINS should be working, I have enough knowledge to be able to change the field names later.
I know its a big ask guys, but i'm pretty sure that if you can give me a little help then i'll be able to learn alot from the workings of the query.
Many Thanks,
Rob
I'm guessing this what you would call an 'advanced' query, although with my knowledge as it is, most things seem pretty advanced lol.
I'm hoping you'll be able to help, I'll try and explain to the best of my abilities what i'm trying to achieve in the hope you'll be able to help. I've also copied in my current efforts (which are shocking) so you can see how poor i am with this kind of thing.
In my database I have the following tables.
member
tblUnits
tblUnitsOwners
tblGroups
Now the concept behind this is that I have a list of members (in the members table), each member is able to own many units, and a unit can be owned by many members. A unit can also be be put into a group, a group can store many units, but a unit may only belong to one group. A member may also own many other members, but a member can only be owned by one member.
So i've constructed the database as best I can, and i'm hoping it will meet my requirements, but if it doesn't then i'm more than happy to change things.
The 'member' table consists of three fields (ID, Name, Owner_id).
The 'tblUnits' table contains all the information on the units, fields are (ID, UnitName, GroupID)
The 'tblUnitsOwners' table contains link data between members and the units, fields are (ID, MemberID, UnitID)
The 'tblGroups' table contains information on the groups, fields are (ID, GroupName, GroupDescription)
Now the desired result is a list of units that are owned by particular user, such as user '1', that can be organised into thier 'groups' and with each box I want a list of other users that own that box, I've tried to illustrate this below.
Group 1 Title
-------------
Unit 1 - User 2
- User 4
- User 5
Unit 3 - User 2
Unit 4 - User 2
Unit 7 - User 5
- User 4
Group 2 Title
-------------
Unit 2 - User 4
Unit 5 - User 8
- User 9
Anyway, i'm mildy proficiant with ColdFusion so grouping the output isn't an issue, its just this query that has got me stumped, and i thought it a little heavy for the CF forum.
Below is a copy of what i've managed to cobble together so far, although i'm pretty convinced its next to useless.
Code:
SELECT tblUnitsOwners.id,
tblUnitsOwners.unitID,
tblUnitsOwners.ownerID,
tblUnits.box_id,
tblUnits.unit_name,
tblUnits.group_id,
tblGroups.id,
tblGroups.group_title,
tblGroups.group_description,
FROM tblUnitsOwners
LEFT JOIN tblUnits
ON tblUnitsOwners.unitID = tblUnits.box_id
LEFT JOIN tblGroups
ON tblUnits.group_id = tblGroups.id
WHERE tblUnitsOwners.ownerID = #arguments.aOwnerID#
ORDER BY tblGroups.id, tblUnits.box_id, tblUnitsOwners.id
You'll notice that the field names are a little different to the ones i've given above, but dont fuss to much, i'm looking for a more general solution as to how my JOINS should be working, I have enough knowledge to be able to change the field names later.
I know its a big ask guys, but i'm pretty sure that if you can give me a little help then i'll be able to learn alot from the workings of the query.
Many Thanks,
Rob