【发布时间】:2011-04-11 21:04:56
【问题描述】:
我想修改我的论坛代码中的查询,以从表 tblProfile 中返回两个字段。该表有两个字段,“EmailAddress”和“EmailVerified”。
这是原始查询:
SELECT *
FROM (SELECT TOP 10 [Scirra].[dbo].[tblForumThread].thread_id,
[Scirra].[dbo].[tblForumThread].MESSAGE,
[Scirra].[dbo].[tblForumThread].message_date,
[Scirra].[dbo].[tblForumThread].show_signature,
[Scirra].[dbo].[tblForumThread].ip_addr,
[Scirra].[dbo].[tblForumThread].hide,
[Scirra].[dbo].[tblForumAuthor].author_id,
[Scirra].[dbo].[tblForumAuthor].username,
[Scirra].[dbo].[tblForumAuthor].homepage,
[Scirra].[dbo].[tblForumAuthor].location,
[Scirra].[dbo].[tblForumAuthor].no_of_posts,
[Scirra].[dbo].[tblForumAuthor].join_date,
[Scirra].[dbo].[tblForumAuthor].SIGNATURE,
[Scirra].[dbo].[tblForumAuthor].active,
[Scirra].[dbo].[tblForumAuthor].avatar,
[Scirra].[dbo].[tblForumAuthor].avatar_title,
[Scirra].[dbo].[tblForumGroup].name
AS groupname,
[Scirra].[dbo].[tblForumGroup].stars,
[Scirra].[dbo].[tblForumGroup].custom_stars,
[Scirra].[dbo].[tblForumGuestName].name
AS guestname,
Row_number() OVER (ORDER BY
[Scirra].[dbo].[tblForumThread].message_date ASC)
AS
rownum
FROM ([Scirra].[dbo].[tblForumGroup]
INNER JOIN ([Scirra].[dbo].[tblForumAuthor]
INNER JOIN [Scirra].[dbo].[tblForumThread]
ON [Scirra].[dbo].[tblForumAuthor].author_id = [Scirra].[dbo].[tblForumThread].author_id)
ON [Scirra].[dbo].[tblForumGroup].group_id = [Scirra].[dbo].[tblForumAuthor].group_id)
LEFT JOIN [Scirra].[dbo].[tblForumGuestName]
ON [Scirra].[dbo].[tblForumThread].thread_id = [Scirra].[dbo].[tblForumGuestName].thread_id
WHERE
[Scirra].[dbo].[tblForumThread].topic_id = 33854
AND ( [Scirra].[dbo].[tblForumThread].hide = 0
OR [Scirra].[dbo].[tblForumThread].author_id = 13405 ))
AS
pagingquery
WHERE rownum BETWEEN 1 AND 10;
我已经选择了字段:
,
[Scirra].[dbo].[tblProfile].EmailAddress,
[Scirra].[dbo].[tblProfile].EmailVerified
但我有点坚持在那个巢中加入!
任何帮助表示赞赏!
编辑
对不起!我需要加入 tblProfile.UserID 和 tblAuthor.author_ID
【问题讨论】:
-
你的
tblProfile表的其他字段是什么?所以我们可以知道如何将它与其他表连接起来。 -
@Lamak 对不起!我需要将 tblProfile.UserID 与 tblAuthor.author_ID 加入
-
@Abe 是的,天哪,我累了,抱歉
标签: sql sql-server inner-join