Possible Duplicate:
Using SQL LIKE and IN together
I have table as below.
create table tab1 (
id int, col1 varchar(20), col2 varchar(20),
col3 varchar(20), col4 varchar(20)
);
I have values inside it as
insert into tab1 values
(1,'column011','column012','column013','column014'),
(2,'column021','column022','column023','column024'),
(3,'column031','column032','column033','column034'),
(4,'column041','column042','column043','column044')
;
Earlier I had requirement as, Find row, where any column HAVE data as column011
. So I executed below query and got what I was desired.
select * from tab1
WHERE 'column011' in (col1,col2,col3,col4);
I have used above against CONCAT_WS
as it was simple query.
select * from tab1
where CONCAT_WS('-', col1, col2, col3, col4) LIKE '%column011%';
Now I got requirement as, Find row, where any column CONTAIN data as mn01
. So I executed below query and got what I was desired.
select * from tab1
where CONCAT_WS('-', col1, col2, col3, col4) LIKE '%mn01%';
However I was thinking to get this done by using simple query (first query). So I tried with below.
select * from tab1
WHERE '%mn01%' in (col1,col2,col3,col4);
Is there any way where I can do what I want by modifying above query? (Last query)