Note that there are some explanatory texts on larger screens.

plurals
  1. POusing % (as LIKE) in IN
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2318126/using-sql-like-and-in-together">Using SQL LIKE and IN together</a> </p> </blockquote> <p>I have table as below.</p> <pre><code>create table tab1 ( id int, col1 varchar(20), col2 varchar(20), col3 varchar(20), col4 varchar(20) ); </code></pre> <p>I have values inside it as </p> <pre><code>insert into tab1 values (1,'column011','column012','column013','column014'), (2,'column021','column022','column023','column024'), (3,'column031','column032','column033','column034'), (4,'column041','column042','column043','column044') ; </code></pre> <p>Earlier I had requirement as, <strong>Find row, where any column HAVE data as <code>column011</code></strong>. So I executed below query and got what I was desired.</p> <pre><code>select * from tab1 WHERE 'column011' in (col1,col2,col3,col4); </code></pre> <p>I have used above against <code>CONCAT_WS</code> as it was simple query.</p> <pre><code>select * from tab1 where CONCAT_WS('-', col1, col2, col3, col4) LIKE '%column011%'; </code></pre> <p>Now I got requirement as, <strong>Find row, where any column CONTAIN data as <code>mn01</code></strong>. So I executed below query and got what I was desired.</p> <pre><code>select * from tab1 where CONCAT_WS('-', col1, col2, col3, col4) LIKE '%mn01%'; </code></pre> <p>However I was thinking to get this done by using simple query (first query). So I tried with below.</p> <pre><code>select * from tab1 WHERE '%mn01%' in (col1,col2,col3,col4); </code></pre> <p>Is there any way where I can do what I want by modifying above query? (Last query)</p> <h2><a href="http://sqlfiddle.com/#!2/b6018/7" rel="nofollow noreferrer">Data at sqlfiddle</a></h2>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload