Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Returning no duplicates when grouping tables

Author  Topic 

monaya
Yak Posting Veteran

58 Posts

Posted - 2010-03-07 : 10:50:39

How do I sort query by most recent pages but only return the book titles, without booktitle duplicates if you have

bookid  booktitle
1 x
2 f
3 g


pageid bookid
1 1
2 1
3 1
4 2
5 2
6 3

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-07 : 10:59:12
[code]select bookid,booktitle,pageid
from
(
select row_number() over (partition by b.bookid order pageid desc) as seq,b.bookid,b.booktitle,p.pageid
from books b
join pages p
on p.bookid = b.bookid
)t
where seq=1[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -