Companies in my db have an ad quota.
Some companies (not all) have a parent company
The companies that have a parent company have no ad quaota themselves, but use the ad quota of their parents.
The companies w/o a parent company have an ad quaota themselves
Now, with the following statement I'm able to get the adquaota if a user's company has a parent.
But as soon as the user's company DOESNT have a parent I get NULL for remainingads...why and how to fix this?
select c.title,
case when c.remainingads>pc.remainingads then c.remainingads else pc.remainingads end
as remainingads
FROM companies c
inner join aspnet_Users au on au.companyid=c.id
left join companies pc on pc.id=c.parentcompanyid
where au.UserName='johndoe'