Girish K G
Girish K G

Reputation: 417

sql SELECT IN with like

how can i write a select query by combining IN and LIKE i have a subquery which returns some records , with threse records i have to select records from another table. the problem is i have to use LIKE clause on the resultant recors of the subquery below is an example of what im trying to do

select * from salary where employeename like (select name from employee)

from salary table i need records which matches the name of employe table. i need to use LIKE . can someone help me please

Upvotes: 6

Views: 29844

Answers (2)

Michael Fredrickson
Michael Fredrickson

Reputation: 37398

I'd go with a join instead of an in... although with the wildcards it will be a full table-scan anyways:

select distinct s.* 
from salary s
join employee e on s.employeename like '%' + e.name + '%'

Upvotes: 24

user1197129
user1197129

Reputation:

check this out.

select * from salary where emp_name like '%aj'

Upvotes: 1

Related Questions