Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. declare @t table (
  2. id int
  3. ,code char(2)
  4. ,descriptor int
  5. )
  6.  
  7. insert into @t
  8. select 1, 'a1', 10
  9. union select 1, 'a1', 20
  10. union select 1, 'a1', 30
  11. union select 2, 'b1', 10
  12. union select 2, 'b1', 20
  13. union select 2, 'b1', 30
  14. union select 2, 'b2', 10
  15. union select 2, 'b2', 20
  16. union select 2, 'b2', 30
  17. union select 3, 'c4', 10
  18. union select 3, 'c4', 20
  19. union select 3, 'c4', 30
  20. union select 3, 'c7', 10
  21. union select 3, 'c7', 20
  22. union select 3, 'c7', 30
  23.  
  24.  
  25. select *
  26. from @t as t
  27. where code = (select min(code) from @t where id = t.id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement