SQL search all columns of a table for text value

后端 未结 3 1949
后悔当初
后悔当初 2021-01-16 02:20

I have a huge table with many columns and I know that this columns sometimes takes some specific value \'MyValue\'. How can I select all the rows in that one specific table

3条回答
  •  野的像风
    2021-01-16 02:49

    You can concatenate all columns with + and then perform a LIKE search:

    SELECT *
    FROM   data
    WHERE  col1 + '#' + col2 + '#' + col3 like '%test%'
    

    Adding a separator (I use #) between the columns ensures you won't get false positives from the concatenation, e.g. if col2 = 'te' and col3 = 'st'

    SQL Fiddle

提交回复
热议问题