Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 581
Girish K G Avatar asked Feb 09 '12 04:02

Girish K G


People also ask

Can I use like in select SQL?

The SQL LIKE condition allows you to use wildcards to perform pattern matching in a query. The LIKE condition is used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement. If playback doesn't begin shortly, try restarting your device.

What is like %% in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

Can you use like with in with an SQL statement?

There is no combination of LIKE & IN in SQL, much less in TSQL (SQL Server) or PLSQL (Oracle). Part of the reason for that is because Full Text Search (FTS) is the recommended alternative.

How do you use like in a query?

In an expression, you can use the Like operator to compare a field value to a string expression. For example, if you enter Like “C*” in an SQL query, the query returns all field values beginning with the letter C. In a parameter query, you can prompt the user for a pattern to search for.


1 Answers

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 + '%'
like image 76
Michael Fredrickson Avatar answered Oct 13 '22 02:10

Michael Fredrickson