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 |
|
louise.hansare.gmail.com
Starting Member
1 Post |
Posted - 2010-06-09 : 06:18:43
|
| Hi,I am really desperate now. I have one table with an auditlog that has a dataid and a date. I have another table with dataid and name. From the second table I can fetch the names I need with a select-statement as there is a where-statement needed. I need the top five distinct names ordered by how they show in the audit-table.Name - Date descName2 - closest date to nowName5 - Name3 -LSwe |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-09 : 06:23:49
|
| Post the structure of your tables,some sample data and the desired output.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-09 : 06:24:20
|
select top 5nt.name,dt.datefrom (select dataid,max(date) as date from auditlog group by dataid)dtjoin nametable nt on nt.dataid=dt.dataidorder by dt.date desc No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-09 : 06:25:40
|
There is also a possible solution using row_number() but I see no reason to do that.  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|