gpt4 book ai didi

mysql在主查询和子查询中搜索

转载 作者:行者123 更新时间:2023-11-29 23:51:10 24 4
gpt4 key购买 nike

在尝试在查询中搜索以下查询时,我可能编写了错误的语法,但我不确定如何纠正它。我也想搜索主表和子查询表中的文本。

这是我的查询

select mytable.*
from mytable
where spam = 0
and deleted = 0
and draft = 0
and (subject like '%guss%' or body like '%guss%' or
(select CONCAT(users.firstname,' ', users.lastname) as fname,users.email
from users where firstname like '%guss%' or lastname like 'guss'))

and id = 24
order by id desc

收到此错误

[Err] 1241 - Operand should contain 1 column(s)

更新#1

select mytable.*
from mytable
where spam = 0
and deleted = 0
and draft = 0
and (subject like '%eli%' or body like '%eli%' or
(select users.firstname
from users where firstname like '%eli%') or
(select users.lastname
from users where lastname like '%eli%'))

and id_receiver = 24
order by id desc

最佳答案

这里的错误:

(select CONCAT(users.firstname,' ', users.lastname) as fname,users.email 
from users where firstname like '%guss%' or lastname like 'guss'))

在子查询中只能返回一列

这是第一列:CONCAT(users.firstname,' ', users.lastname) as fname

这是第二列:users.email

关于mysql在主查询和子查询中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25647751/

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