I’ve tried checking out this question sql – distinct + select and can’t seem to get it tailored correctly to my situation. I am also not on the sql dev team so I don’t know all the in’s and out’s of the database. I’m shooting in the dark here on a test DB. Here is a pseudo sample of my current query:
select a.name, b.col1,
from name a, amount b
where a.identifier=b.acctid
and b.col1 != 'test'
Example of what is currently returned by query:
a.name | b.col1
Jeff 1
Jeff 333
Jeff 77
Jeff 1
Jeff 14
Bob 22
Bob 4
Bob 5
Bob 6
And I would like for the results of the query to return the first n(a number I choose) results that are unique based on ColA. For example if n was 2:
a.name | b.col1
Jeff 1
Jeff 333
Bob 22
Bob 4
For SQL Server 2005+ you can use analytical functions:
I also changed your query to use explicit joins.