Mysql - check occurrence in all fields

1

How to check the occurrence of a string in any field?

Nothing specific like WHERE campo1 = "abcd" , since I want to check the occurrence in any field.

That is something different also from the extensive OR, to sweep each field, something like: WHERE campo1 = "abcd" OR campo2 = "abcd" OR campo3 = "abcd" , ..

I think there is an alternative beyond this last one, yes?

    
asked by anonymous 11.09.2015 / 21:07

1 answer

1

If you can use a programming language, this task is not so complicated. The idea is to do two queries to the first one by taking all the fields of a certain table (maybe the type of type), then in the main query, make a in() invertido instead of passing values to it, pass the list of columns.

Ex:

Returns the names of the columns.

SELECT column_name FROM information_schema.columns WHERE table_name = 'tabela'

The second query would be:

SELECT * FROM tabela where 'valor' IN(nome, email, endereco, outra_coluna)
    
11.09.2015 / 22:30