gpt4 book ai didi

php - 使用 select 时子查询在 mysql 中返回多于 1 行

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

我有两个表,用户和主题。

表用户

CREATE TABLE IF NOT EXISTS `user` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`usertype` int(11) DEFAULT '0',
`useraccesskey` varchar(80) DEFAULT NULL,
`userphone` varchar(80) DEFAULT NULL,
`userpassword` varchar(80) DEFAULT NULL,
`usernickname` varchar(80) DEFAULT NULL,
`userphoto` varchar(80) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

表格主题

CREATE TABLE IF NOT EXISTS `topic` (
`topicid` int(11) NOT NULL AUTO_INCREMENT,
`btid` int(11) NOT NULL,
`topictitle` varchar(80) NOT NULL,
`topiccontent` text NOT NULL,
`topicisdel` int(11) NOT NULL,
`topicdate` varchar(80) NOT NULL,
`authorid` int(11) NOT NULL,
`useraccesskey` varchar(80) NOT NULL DEFAULT '0',
`topicistop` int(11) NOT NULL DEFAULT '0',
`topicishot` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`topicid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1605 ;

我使用这个 sql 查询来列出所有信息

select b.*, (select userphoto from user u where u.useraccesskey = b.useraccesskey) as headpic, (select usernickname from user u where u.useraccesskey = b.useraccesskey) as nickname from topic b where b.topicisdel = 0 and b.btid = 3 order by b.topicistop desc, b.topicishot desc, b.topicid desc"

但结果告诉我子查询返回超过1行,但我检查了所有信息,没有,我不知道为什么,请帮助我,谢谢。

最佳答案

所以看起来你正在追求类似这样的东西 - 尽管没有数据集和结果集,但总是愚蠢地很难确定......

select b.*
, u.userphoto headpic
, u.usernickname nickname
from topic b
join user u
on u.useraccesskey = b.useraccesskey
where b.topicisdel = 0
and b.btid = 3
order
by b.topicistop desc
, b.topicishot desc
, b.topicid desc

关于php - 使用 select 时子查询在 mysql 中返回多于 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30408511/

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