sql中1对多的两个表查询,并要求要结合到一行,如何作?

如下两个查询:SELECTTOP1topic.topic_title,userr.user_loginname,topic.topic_timeFROMtopicINNE... 如下两个查询:
SELECT TOP 1 topic.topic_title, userr.user_loginname, topic.topic_time
FROM topic INNER JOIN
userr ON topic.user_id = userr.user_id
WHERE [topic].section_id=1
ORDER BY [topic].topic_id DESC

SELECT section_name, section_topiccount,
section_replycount
FROM [section]
WHERE [section].section_flag=1

我已经作出的 一个 如下(有错):
SELECT [section].section_name, [section].section_topiccount,
[section].section_replycount, topic.topic_title,
userr.user_loginname, topic.topic_time
FROM [section] INNER JOIN
topic ON [section].section_id = topic.section_id INNER JOIN
userr ON topic.user_id = userr.user_id
WHERE [section].section_flag=1 AND [topic].section_id=1
AND [topic].topic_id=(SELECT TOP 1 * FROM topic WHERE [topic].section_id=1 ORDER BY [topic].topic_id DESC)
报错内容是:
服务器: 消息 116,级别 16,状态 1,行 1
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。

哪位大虾帮个忙!!!!
我建表如下:
CREATE TABLE [dbo].[section] (
[section_id] [int]
[section_name] [nvarchar]
[user_id] [int]
[section_topiccount]
[section_replycount]
[section_flag] [int]
[section_remark] [nvarchar]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[topic] (
[topic_id] [int]
[section_id] [int]
[expression_id] [int]
[topic_title] [nvarchar]
[user_id] [int]
[topic_content] [ntext]
[topic_time] [datetime]
[topic_click] [int]
[topic_flag] [int]
[topic_maketop] [int]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[userr] (
[user_id] [int]
[user_loginname] [nvarchar]
[user_password] [nvarchar]
) ON [PRIMARY]
GO
展开
 我来答
badkano
2007-10-14 · 知道合伙人体育行家
badkano
知道合伙人体育行家
采纳数:144777 获赞数:885359
团长

向TA提问 私信TA
展开全部
AND [topic].topic_id=(SELECT TOP 1 * FROM topic WHERE [topic].section_id=1 ORDER BY [topic].topic_id DESC)

这个地茄饥孙方,把*换肢销成颤链topic_id
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式