In addition to what LoztInSpace stated.
Do you want to evaluating whether OrderId is equal to empid ?
That is what you are doing in the red hightlighted text below.
If you want to evaluate mgrid value, it suffices to say
WHERE mgrid is NULL
Since you are joining HR.Employees and Sales.Orders tables, you dont need another select statement in your where clause.
Run the following query to see all the data available to you when you join the above two tables:
SELECT * FROM HR.Employees H INNER JOIN Sales.Orders S
ON H.empid = S.empid;
Originally posted by marcelkouatly
SELECT lastname, firstname
FROM HR.Employees INNER JOIN Sales.Orders
ON HR.Employees.empid = Sales.Orders.empid
WHERE orderid =
(SELECT empid FROM HR.Employees
WHERE mgrid = NULL);