sql - how to know which column is matched when filter the records by multiple columns compare -


i have table "table1" like

name col1 col2 col3 col4    1    2    3    4 

i want filter table

"select * table1 (col1=1 or col2=1 or col3=1 or col4=1)" 

i expect result is

name col_name    col1 

is possible sql statement?

you not limited selection of columns in select list, can use expressions. example, can use this:

select     name, -- more columns needed     case     when col1=1 'col1'     when col2=1 'col2'     when col3=1 'col3'     when col4=1 'col4'     else null end col_match table1 (col1=1 or col2=1 or col3=1 or col4=1) 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -