我有两个表,用户和主题。使用select时子查询返回多于1行的mysql
表用户
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"
但结果告诉我Subquery returns more than 1 row
,但我检查了所有的相关信息,没有,我不知道为什么,请帮助我,谢谢。
你的意思是说没有记录,但它说有更多的记录在那里? –
@anantkumarsingh对不起,我的意思是有一些记录,但不一样,我不知道为什么,谢谢。 – pidan
你究竟想要做什么以及结果如何,目前尚不清楚。 –