Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.60/5 (4 votes)
Hi,

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

SQL
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.
Posted
Comments
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..
SQL
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)


ref.
http://stackoverflow.com/questions/14116292/match-multiple-columns-with-same-value-sql[^]

MSDN SQL IN[^]
 
Share this answer
 
Comments
Peter Leow 6-Feb-15 5:55am    
5ed!
/\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??
example???
[no name] 6-Feb-15 9:05am    
maybe something like this:

WHERE 'a' IN (c1, c2, c3) OR 'b' IN (c1, c2, c3, c4)

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