Wednesday, May 2, 2012
Use TOP and DISTINCT together in t-sql
Surprisingly it is difficult to use TOP and DISTINCT together in SQL.
This will not work:
select top 2 distinct t.ID as tID, t.Name as tName from Table1 order by tID
It can be replaced by something like this to work:
select top 2 * from
(select distinct t.ID as tID, t.Name as tName from Table1 t) y
order by tID
Also see some other web links, such as Here
Subscribe to:
Post Comments (Atom)
1 comment:
select distinct top x fields from table ;
Post a Comment