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
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.
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.
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.
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.
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 + '%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With