我有兩個表,用戶和主題。使用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
你究竟想要做什麼以及結果如何,目前尚不清楚。 –