程序笔记
随心而记

SELECT * FROM TB1 ORDER BY [name]

id     name
------ ----------
1      A        
5      A        
6      A        
2      B        
3      B        
4      C        

(6 行処理されました)

----------------------------------------------------------------------------

select * from tb1 as tb2 where [id] = (select min([id]) from tb1 where [name] = tb2.[name])

********************************

id     name
------ ----------
1      A        
2      B        
4      C        

(3 行処理されました)

----------------

select tb1.[id],isnull(tb2.[name],'') as [name] from tb1
left join
(select min([id]) as [id],[name] from tb1 group by [name]) tb2
on tb1.[id]= tb2.[id]
order by tb1.[name]

********************************

id     name
------ ----------
1      A        
5               
6               
2      B        
3               
4      C        

(6 行処理されました)

posted on 2009-06-05 13:52    阅读(681)  评论(0编辑  收藏  举报