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 展开
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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询