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 |
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2007-10-16 : 13:02:19
|
| how do i get an entire record returned when looking for only column to be unique?basically i have 3 columnsid, tranid, appliedtranidtranid can have multiple appliedtranidsi need to grab the top 10 distinct tranids but i need the entire record |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-16 : 13:30:03
|
| I swear these DISTINCT queries are breeding! We've had several in the last couple of days.So if a [tranid] has mutliple values of [appliedtranid] which one do you want?MIN(appliedtranid) or MAX(appliedtranid) or Average(appliedtranid) ... or something else?Kristen |
 |
|
|
Kristen
Test
22859 Posts |
|
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2007-10-16 : 13:38:23
|
| actually it doesnt matter -- they all link back to the same companyso is it safe to say that if i goselect top 10 tranid, min(appliedtranid)from tablegroup by tranidit will return the top 10 distinct tranid |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-16 : 13:50:29
|
| Yup, It would be a good idea to ahve an ORDER BY as well, otherwise you will get random results each time.Maybe:ORDER BY COUNT(*) DESC, tranidto get the ones with the most appliedtranid first, and then use [tranid] as a tie breakKristen |
 |
|
|
|
|
|