It's weird how I can cruise along, writing dozens of queries, and suddenly find myself stumped by something that I'm nearly certain is straightforward, but some kind of block in my brain is in the way. I appreciate very much your help.
4 tables (that matter here):
My goal is to create a query that include, basically, the whole combination of Feature and Section, and then for a given user, a column that indicates to me whether there's a linking between User and Feature for that table. So, for example, here's some example data:
So, in this case, we'd want all of the Features to be returned along with their section name, and and indicator whether a given user had that feature associated (and whether Icon is true or false).
The result of the query, if I specify UserID = 1, would look something like this:
"UserLinked" is a made-up field that indicates whether there's a matching UserFeature record for a given User and Feature. I'd guess that UserFeature.Icon would need to always be "True" or "False" (as a Yes/No field), and it's fine if it just defaults to False instead of Null.
So... I've easily managed the list of all Features with their sections (simply inner join), but when I try to add in the UserFeature field without specifying "Icon" or anything else in the columns I request, it compresses the results so that I only get the columns where all 3 have something (even with a LEFT join). If I add anything from the UserFeature table to the columns I want returned (like UserFeature.Icon), it just blows on syntax. And none of this even touches the need for a true/false added "UserLink" field.
Sorry, that was a lot. Any clues on where to head with this?
4 tables (that matter here):
Code:
[b]Section[/b]
ID [i](PK)[/i]
Name
[b]Feature[/b]
ID [i](PK)[/i]
Name
SectionID [i](FK to Section table, ID column)[/i]
[b]User[/b]
ID [i](PK)[/i]
Name
[b]UserFeature[/b] [i]("joining" table)[/i]
UserID [i](FK to User table, ID column)[/i]
FeatureID [i](FK to Feature table, ID column)[/i]
Icon
Code:
[b]Section[/b]
[u]ID[/u] [u]Name[/u]
1 Apps
2 Depts
[b]Feature[/b]
[u]ID[/u] [u]Name[/u] [u]SectionID[/u]
1 Calendar 1
2 Search 1
3 Accounting 2
4 HR 2
5 Sales 2
[b]User[/b]
[u]ID[/u] [u]Name[/u]
1 Bob
2 Jan
[b]UserFeature[/b]
[u]UserID[/u] [u]FeatureID[/u] [u]Icon [/u]
1 1 True
1 2 True
1 4 False
So, in this case, we'd want all of the Features to be returned along with their section name, and and indicator whether a given user had that feature associated (and whether Icon is true or false).
The result of the query, if I specify UserID = 1, would look something like this:
Code:
[u]Section.Name[/u] [u]Feature.Name[/u] [u]UserLinked[/u] [u]UserFeature.Icon[/u]
Apps Calendar True True
Apps Search True True
Depts Accounting False
Depts HR True False
Depts Sales False
So... I've easily managed the list of all Features with their sections (simply inner join), but when I try to add in the UserFeature field without specifying "Icon" or anything else in the columns I request, it compresses the results so that I only get the columns where all 3 have something (even with a LEFT join). If I add anything from the UserFeature table to the columns I want returned (like UserFeature.Icon), it just blows on syntax. And none of this even touches the need for a true/false added "UserLink" field.
Sorry, that was a lot. Any clues on where to head with this?