SQLite 选择具有类似条件的相反查询
我正在尝试在 php 中编写一个查询,该查询将从数据库中选择部分与字符串匹配的行。
通过示例更好地解释:
假设我的数据库有一个名为 numberString
的字段,其值为“abcd”。我想编写一个查询,给定“123abcd”,将返回数据库该行的字段。
SELECT mood
FROM USERS
WHERE numberString like '%$giveNumberString'"
$giveNumberString
是函数参数(即我想要查找的字符串),
但我认为这两个 numberString
和 '%$givenNumberString'"
应该像其他方式一样,以便查询按预期工作。有没有办法做到这一点?
好的,表格看起来像这样:
id | username | numberString | mood
-------------------------------------
1 | myUsrNam | abcd | happy
现在我想,给定“123abcd”,检索那个人的情绪。换句话说,将 123abcd 与 abcd 进行匹配。
I'm trying to write a query in php that will select a row from a database that partially matches a string.
Better explained via an example:
Say my DB has a field called numberString
, with value 'abcd'. I want to write a query that, given "123abcd", will return a field of that row of the database.
SELECT mood
FROM USERS
WHERE numberString like '%$giveNumberString'"
$giveNumberString
is the functions parameter (i.e. the string that I want to look for)
But I think those two numberString
and '%$givenNumberString'"
should be like the other way around in order for the query to work as expected. Is there a way to do this?
Ok the table looks like this:
id | username | numberString | mood
-------------------------------------
1 | myUsrNam | abcd | happy
Now I want, given "123abcd", to retrieve the mood of that person. In other words to match 123abcd against abcd.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是合法的语法,但让我尝试一下疯狂的猜测:你尝试过吗
?
I'm not sure this is a legal syntax, but let me try a wild guess: have you tried
?