Left outer Join SQL Server Problem - not returning enough rows?

The condition that userid='a' should be a join condition: select distinct f. Name, f. Type, case when uf.

Userid = 'a' then 1 else 0 end as Active from filter f left outer join userfilter uf on f. Id = uf. Filterid and uf.

Userid = 'a.

Great, this one works for the current case and all other cases (no other users, other users have the same filters, other users have different filters, current user got 0 filters, etc. )! – Dennis Röttger Jun 9 at 12:31.

You have a where clause including only rows where uf. Userid ='a' or null Try: select distinct f. Name,f.

Type, case when uf. Userid is null then 0 else 1 end as Active from filter f left outer join userfilter uf on f. Id = uf.filterid.

– Dennis Röttger Jun 9 at 11:38 If I simply remove the where-clause I will receive the Dataset "User: B, Filter: 3, Active: 0" giving me essentially the right information, but I'd like to receive User: NULL instead of B. – Dennis Röttger Jun 9 at 11:42 See my edit above – BonyT Jun 9 at 11:54 Yes, that's the point, because of your edit this is my current state. There will be a row "User: B Filter: 3 Active: 0", which is correct, but should display User: NULL instead of B.

Furthermore, if I activate Filter '3' for User A too, I receive 2 Rows: User A Filter 3 Active 1 and User B Filter 3 Active 0. – Dennis Röttger Jun 9 at 11:57.

Corina's answer is correct. Here is another way to express the same thing (just to show you a different way to write the same query): select Filter. Name, Filter.

Type, case when x. UserId IS NULL then 0 else 1 end as Active from Filter left join ( select * from UserFilter where UserFilter. UserId = 'a' ) x on Filter.Id = x.FilterId.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions