Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use many LIKE conditions in SQL easily? [duplicate]

Tags:

sql

sql-like

I want to use many LIKE conditions in my query. I couldn't find a practical solution. I tried CONTAINS but it doesn't work.

Instead of using this

where EIO.DigiAddress like '%[email protected]%'
or EIO.DigiAddress like '%[email protected]%'
or EIO.DigiAddress like '%[email protected]%'

I want to use something like this:

CONTAINS(EIO.DigiAddress,'%[email protected]%', '%[email protected]%', '%[email protected]%')

OR

EIO.DigiAddress IN ('%[email protected]%', '%[email protected]%', '%[email protected]%')
like image 717
cihadakt Avatar asked Apr 19 '13 11:04

cihadakt


1 Answers

Try this:

Create a temp table:

CREATE TEMPORARY TABLE temp (
    alternate VARCHAR(20)
);

then:

INSERT INTO temp
VALUES ('%[email protected]%'), ('%[email protected]%'), ('%[email protected]%');

Select:

SELECT t.*
FROM tbl t JOIN temp p ON (t.col LIKE p.alternate);
like image 143
Vinayak Pahalwan Avatar answered Sep 28 '22 17:09

Vinayak Pahalwan