Using "LIKE" with a "IN" clause full of lines

I want to do soft string matching in a table, for example:

SELECT * FROM emailaddresses where addr in ('john@google.com', 'jim@google.com')

But if the table " JOHN@google.com " has the value addr, I want this to be returned.

Example:

SELECT * FROM emailaddresses where addr LIKE in ('john@google.com', 'jim@google.com')

How to do it?

+5
source share
6 answers

put the values ​​in a table and use a clause join, not in:

SELECT * FROM emailaddresses as ea
INNER JOIN addresses as a
ON ea.address like '%' + a.address + '%'
+8
source

You can use the LOWER function

SELECT * FROM emailaddresses where LOWER(addr) in ('john@google.com', 'jim@google.com')

Which converts all addr to lowercase, in which you can compare the results with what you want.

+3
source

, LIKE , , , , , LIKE.

SQL Server .

, , . , ( IN ).

SELECT *
FROM emailaddresses
WHERE addr COLLATE SQL_Latin1_General_CP1_CI_AS 
IN (
    'john@google.com' COLLATE SQL_Latin1_General_CP1_CI_AS
    ,'jim@google.com' COLLATE SQL_Latin1_General_CP1_CI_AS
)

LIKE - addr LIKE '%@google.com"

+1

Try using a cross join in a table containing a list of email addresses you want to find:

declare @email table(
email_check nvarchar(500) not null)

insert into @email(email_check)
values('jack@google.com')
insert into @email(email_check)
values('john.@google.com')



select hit, ID, EMAIL_ADDRESS from (
    select CHARINDEX(email_check, lower(EMAIL_ADDRESS)) hit, ID, EMAIL_ADDRESS
    from Table_With_Email_Addresses
    ,@email
) t
where hit > 0

No need to “seem like”, because it will parse the string to find a match. Hooray!

0
source
select * from HotelAmenities_ 
where Pamenities in (
            select distinct(pamenities) 
            from HotelAmenities_ 
            where pamenities like '%Swimming%'
        )
0
source

We can use the "LIKE-In" approach together in SQL, but in a slightly different style, for example, below:

SELECT * 
FROM emailaddresses 
WHERE addr LIKE 'john@google.com' OR addr LIKE 'jim@google.com'
0
source

All Articles