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.
| Author |
Topic |
|
crugerenator
Posting Yak Master
126 Posts |
Posted - 2007-06-12 : 09:47:28
|
| SELECT post.C_ID, post.Comment, post.Title, post.Date, authors.U_NameFROM authors INNER JOIN post ON authors.A_ID = post.A_IDORDER BY C_ID DESCThat's the query I'm using, and I was hoping there is a way to use the WHERE clause to have only the 5 highest #'s from my primary key, which is A_ID IDENTITY(1,1).What would be the best way for me to do this? I also have date as a datetime, but then I could be getting more or less than 5 results in my query. Thanks |
|
|
readysetstop
Posting Yak Master
123 Posts |
Posted - 2007-06-12 : 09:53:10
|
| Using 'TOP' in the select would do it.____________________________________________________________________________________"Believe in those who are seeking the truth. Doubt those who say they have found it." -Andre Gide |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-12 : 09:53:50
|
| Is this?SELECT post.C_ID, post.Comment, post.Title, post.Date, authors.U_NameFROM authors INNER JOINpost ON authors.A_ID = post.A_IDwhere post.A_ID in (Select top 5 A_ID from post order by A_ID DESC)ORDER BY C_ID DESCMadhivananFailing to plan is Planning to fail |
 |
|
|
crugerenator
Posting Yak Master
126 Posts |
Posted - 2007-06-12 : 10:07:51
|
| ThanksSELECT TOP (# rows you want returned) rest of querySELECT TOP(5) post.C_ID, post.Comment, post.Title, post.Date, authors.U_NameFROM authors INNER JOINpost ON authors.A_ID = post.A_IDORDER BY C_ID DESCworked perfectly |
 |
|
|
|
|
|
|
|