Reputation: 131
I have a T-SQL query that has a subquery listing 2 names:
Code:
Select LastName
From Managers
Where Type = prefix;
I need to have the outer query use this above sub-query in something like an 'IN' statement, but it's not an exact match, but rather a BEGINS WITH. Something like the following with + '%':
Select *
From Employees
Where LastName In (Select LastName + '%'
From Managers
Where Type = prefix)
Desired query would return back outer query results such as:
...but, this is not working. I get 0 results.
Upvotes: 0
Views: 45
Reputation: 131
Got it with similar to:
select * from employees e
inner join Managers m on e.lastname like m.lastname + '%' and m.type = prefix
Upvotes: 0
Reputation: 1269753
You can use exists
. Presumably, you intend something like this:
Select e.*
from Employees e
where exists (select 1
from managers m
where type = prefix and
e.LastName like m.LastName + '%'
)
Upvotes: 3