SELECT DISTINCT Database1.dbo.tblCustomers.SiteNum
FROM Database1.dbo.tblCustomers
LEFT OUTER JOIN tblWebUsers on tblWebUsers.SiteNum = Database1.dbo.tblCustomers.SiteNum
WHERE **tblWebUsers.ID = '4'**
This returns all sitenums relating to a webuser id but how do i do the opposite? i.e. return all site numbers not associated to a webuser id – I have tried not in (4) but it just returns all webusers site numbers that don’t have an id … I want it from database1
It’s still not clear what the opposite would be (we don’t have any sample data and expected results to work with, and only you can see your actual database), but I’d note that having
tblWebUsers.ID = '4'in your where clause is forcing the left join to become an inner join.This may be closer to what you want:
Or more editable into the final form you’re seeking.
In fact, I think that this is what you’re wanting:
That is, you want to find rows from
tblCustomerswhich do not have a row intblWebUserswithIDequal to 4. But again, it would be better if you could more clearly explain what you’re trying to achieve, hopefully with sample data and expected results.