Ahmed Hassan Ahmed Hassan - 4 months ago 8
SQL Question

SQL query condiction help please

I have three tables

Users ( ID - Name )
Services (ID - Name)
UserServices ( ID - USerID- ServiceID )


I want to select serviceName that not belong to user
eg
if i have three users and 10 services

First user belong to 3 services so i want to select other 7 services only

regards

Answer

There is many way to get the results you want, this is one :

SELECT S.ID, S.Name
FROM  UserServices AS US
INNER JOIN Services AS S ON US.ServiceID = S.ID
WHERE US.UserID <> @UserID