Click here to Skip to main content
14,733,912 members
Please Sign up or sign in to vote.
4.60/5 (4 votes)

Today i am facing a problem not an issue, i googled but not found any appropriate method to compare more than 20 or 50 columns together in sql server, MYSQL. i.e. if i have a query like

select * from table1 where (col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15,col16,col17,col18,col19,col20) in ('test')

that's means records return only when at least one of the column should have 'test' value.
Thanks7872 6-Feb-15 5:36am
Why you are doing this way? It will be useful to provide a better solution if you can elaborate your question.

1 solution

Use Sql IN claus like this..
select * from table1 where 'test' in(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15,col16,col17,col18,col19,col20)


Peter Leow 6-Feb-15 5:55am
/\jmot 6-Feb-15 5:57am
thank you.
Er. Vikas Sangal 6-Feb-15 7:34am
Thanks for your solution.
if have to compare more than two string values then what to do?
/\jmot 6-Feb-15 7:50am
like what??
[no name] 6-Feb-15 9:05am
maybe something like this:

WHERE 'a' IN (c1, c2, c3) OR 'b' IN (c1, c2, c3, c4)
/\jmot 6-Feb-15 15:46pm
yes,thank you :)
[no name] 6-Feb-15 15:11pm
Also my 5.
Did not know that this is possible (most probably there is no real need for it), thank you for sharing. Ok, some SQL Server do not support it, but MS-SQL supports it.
/\jmot 6-Feb-15 15:43pm
thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900