 <p>Here is a query. This will make sure in each column(any) any of the 1,2,3,4,5 number exists i.e. 5 columns have a different number in them</p> <pre><code>select *, ((LENGTH(concat(cola,colb,colc,cold,cole))) - LENGTH(REPLACE(concat(cola,colb,colc,cold,cole), '1', ''))) as one, ((LENGTH(concat(cola,colb,colc,cold,cole))) - LENGTH(REPLACE(concat(cola,colb,colc,cold,cole), '2', ''))) as two, ((LENGTH(concat(cola,colb,colc,cold,cole))) - LENGTH(REPLACE(concat(cola,colb,colc,cold,cole), '3', ''))) as three, ((LENGTH(concat(cola,colb,colc,cold,cole))) - LENGTH(REPLACE(concat(cola,colb,colc,cold,cole), '4', ''))) as four, ((LENGTH(concat(cola,colb,colc,cold,cole))) - LENGTH(REPLACE(concat(cola,colb,colc,cold,cole), '5', ''))) as five from tests having one = 1 AND two = 1 AND three = 1 AND four = 1 AND five = 1 </code></pre>