想要使用多个术语时查询中LIKE子句的顺序 [英] Order of LIKE clause in query when wanting to use multiple terms

查看:64
本文介绍了想要使用多个术语时查询中LIKE子句的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有查询

SELECT * FROM images WHERE tags LIKE '%example%hello%'

我希望数据库选择在标签"列中具有"example"和"hello"的行以任何顺序排列,例如:

I would like the database to select rows which have 'example' and 'hello' in the 'tags' column in any order, as in:

包含"hello,test,example","example,hello,test"或此顺序的任何其他变体的行. 即使不使用LIKE,这也是可能的吗?这些行必须全部包含LIKE指定的所有内容.

A row with 'hello, test, example', also 'example, hello, test' or any other variation of this order. Is this possible, even without using LIKE? The rows must all contain everything specified with LIKE.

例如,当我在查询中提供"example"和"hello"时,返回的行必须同时包含"example" "hello".

Such as, when I provide 'example' and 'hello' in the query, rows returned must contain both 'example' and 'hello'.

推荐答案

您可以尝试使用简单的OR快速解决方案:

You could try a simple OR for a quick solution:

SELECT * FROM images WHERE tags LIKE '%example%' OR tags LIKE '%hello%'

编辑

要解决您的修改,可以改用AND:

To address your edit, you can use AND instead:

SELECT * FROM images WHERE tags LIKE '%example%' AND tags LIKE '%hello%'

这篇关于想要使用多个术语时查询中LIKE子句的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆