gpt4 book ai didi

mysql - 选择同一字段中具有不同值的行

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:49 24 4
gpt4 key购买 nike

你好,我对 sql 很在行,所以我需要你的帮助。

我有一个名为 property 的表。现在我想在同一字段中检索具有不同值的行。我尝试使用 LIKEAND 但没有得到任何结果。

表格:

id    user_id   title    approved
-- ------- ----- --------
1 60 one 1
2 60 one 1
3 60 one 1
4 60 two 1
5 60 three 1

SQL 查询:

SELECT *
FROM `property`
WHERE `user_id` =60
AND `approved` =1
AND `title` like '%one%'
AND `title` like '%two%'

我想要这个结果:

id    user_id   title    approved
-- ------- ----- --------
1 60 one 1
2 60 one 1
3 60 one 1
4 60 two 1

有什么想法吗?

谢谢。

最佳答案

如果 title like '%one%' AND title like '%two%',您将查找同时包含“one”和“two”的标题。你想要一些带有“一个”或“两个”的

SELECT *
FROM `property`
WHERE `user_id` =60
AND `approved` =1
AND (`title` like '%one%' OR `title` like '%two%')

关于mysql - 选择同一字段中具有不同值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com