在mysql中使用单个关键字的单个where条件搜索表的所有列

Search all columns of a table using a single where condition with single keyword in mysql(在mysql中使用单个关键字的单个where条件搜索表的所有列)
本文介绍了在mysql中使用单个关键字的单个where条件搜索表的所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 64 个不同字段的表格.我将在其中使用单个关键字进行搜索,结果应与任何字段中的关键字匹配.给点建议.

I have a table which consists of 64 different fields. i am going to search with a single keyword in it, Results should match the keyword from any field. Give some suggestions.

推荐答案

SELECT * FROM `some_table`
WHERE
CONCAT_WS('|',`column1`,`column2`,`column3`,`column4`,`column64`) # single condition, many columns
LIKE '%VT%'

瞧.

'|'顺便说一下,分隔符是为了防止您找到巧合的匹配,例如,第 1 列以V"结尾,第 2 列以T"开头,这会使您在搜索VT"时出现误报.

The '|' separator, by the way, is to prevent you finding coincidental matches where, e.g., column1 ends in 'V' and column2 starts with 'T', which would give you a false positive in a search for "VT".

我不确定上述方法是否比 OR 方法更快(我猜它们的速度相同),但如果您正在编写查询,它肯定涉及较少的输入手动.

I'm not sure if the above method is faster than the OR method (I would guess they're the same speed) , but it definitely involves less typing if you're writing the query by hand.

这篇关于在mysql中使用单个关键字的单个where条件搜索表的所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)