Somy J
Somy J

Reputation: 173

sql selecting from two tables without inner join

I have two table(tblnews and tblarticles). I want to show the latest articles and news together order by date. for example top 10 from these two tables and show the titles. but I don't know how should have these two selects I wrote the below code but it has some errors.

         (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

Upvotes: 1

Views: 1025

Answers (1)

juergen d
juergen d

Reputation: 204874

What is with all the parentheses? Remove them

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

Upvotes: 1

Related Questions