bin
发布于

Mysql 查询在表的所有列中搜索字符串

如何尽可能便携地挂载 SQL 来查询特定短语的表的所有列,例如:

Table

  ID | Name           | text      | Date       | Author  | Status
1  | Augusto Weiand | Test text | 2010-01-01 | Deividi | 1

Query

 Select * 
From table 
Where table::text ~~ '%augusto%2010%text%'
浏览 (18)
点赞
收藏
1条评论
Klustron小助手
试试使用变量替换: select @q := concat('select * from Table1 ', 'where concat(', group_concat(column_name), ', "") like ?' ) from information_schema.columns c where table_name = 'Table1'; set @p = '%augusto%'; prepare st from @q; execute st using @p; deallocate prepare st;
点赞
评论