使用 MySQL like 语句 [英] Using the MySQL like statement

查看:52
本文介绍了使用 MySQL like 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使 like 语句起作用,但是只有在它完全匹配时才起作用,因为我希望显示所有匹配项.因此,假设您在搜索栏中搜索和",我希望它返回所有包含该词和标题的帖子 下面是代码

Hello i am trying to get the like statement working however it will only work if its an exact match where as im am hoping to show all matches. So lets say you search "and" in the search bar, i want it to come back with all posts that have the word and in the title Below is the code

SELECT * FROM `Posts` WHERE title LIKE 'and'

在我费心创建实际的完整脚本之前,我只是想在 phpmyadmin 中使用 sql 选项卡使其工作.

Just trying to get this working in the phpmyadmin with the sql tab before i bother creating the actual full script.

有谁知道我怎样才能让上面的语句显示所有带有和标题的帖子?

Does anyone know how i can get the above statement to show all posts with and in the title?

感谢您的帮助.

推荐答案

你必须在 and 前后加上 %.

You have to put % before and after and.

SELECT * FROM `Posts` WHERE title LIKE '%and%'

这篇关于使用 MySQL like 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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