我有两张桌子(tblnews和tblarticles)。 我想按日期一起显示最新的文章和新闻。 例如,这两个表中的前10名并显示标题。 但我不知道应该如何使用这两个选项编写下面的代码,但它有一些错误。
(select top (10)(([NewsId]) as id,([NewsTitle]) as title,([NewsDate]) as date,[NewsActive]) from [tblnews]
where ([NewsActive]='true')) Order by date Desc)
UNION ALL
(Select Top(10)([ArticleId] as id,[ArticleTitle] as title ,
[ArticleDate] as date, [ArticleActive])
From [tblarticle] where [ArticleActive]='true'
order by date DESC )order by date DESC
答案 0 :(得分:1)
所有括号是什么?删除它们
select * from
(
(select top (10) [NewsId] as id, [NewsTitle] as title, [NewsDate] as date, [NewsActive]
from [tblnews]
where [NewsActive]='true'
Order by date Desc)
UNION ALL
(Select Top(10) [ArticleId], [ArticleTitle], [ArticleDate], [ArticleActive]
From [tblarticle]
where [ArticleActive]='true'
order by date DESC )
) tmp
order by date DESC