This query works:
SELECT u.UserId, u.GroupId, u.username,
gp.PreferenceId, gp.Properties, gp.Override
FROM dbo.UserTable u
Inner JOIN
dbo.GroupPreferences gp ON gp.GroupID = u.GroupId
WHERE (u.UserName = 'myUserId')
But the same query inside another query doesn't. I get the errors "Invalid column name 'GroupId'" and "Invalid Column Name 'UserId'". I imagine there is an extra ( or ) somewhere; please help me find it!
The outer query:
SELECT coalesce(t1.PreferenceId,up.preferenceId)
as preferenceId, CASE t1.override WHEN 1 THEN COALESCE
(up.properties, t1.properties)
When 0 then t1.properties
ELSE up.properties END AS Properties
FROM
(SELECT u.UserId, u.GroupId, u.username,
gp.PreferenceId, gp.Properties, gp.Override
FROM dbo.UserTable u
Inner JOIN
dbo.GroupPreferences gp ON gp.GroupID = u.GroupId
WHERE (u.UserName = 'myUserId')) t1
full OUTER JOIN
(select preferenceId, properties from UserPreferences u
inner join userTable t on u.userId = t.userId and u.GroupId =
t.GroupId where userName = 'myUserId') up
ON t1.GroupId = up.GroupID AND t1.UserId = up.UserId
AND t1.PreferenceId = up.PreferenceId