[T-SQL] Select Distinct for 4 columns but return all columns.. how? |
Select Distinct for 4 columns but return all columns.. how? Posted: 29 Jun 2013 08:54 AM PDT dear friends,I have a table with too manly fields. there are duplicate records in in rows BUT ONLY for some fields. I need to use DISTINCT on 4 columns and then return all rows.or at least I should get ID value of records in result so I can real all columns with code.lets say:col1 col2 col3 col4 col5 col6a1 AA BB a4 CC a6b1 b2 b3 b4 CC b6c1 AA BB c4 CC c6result must be:a1 AA BB a4 CC a6b1 b2 b3 b4 CC b6here's test code:CREATE TABLE [dbo].[Table_2]( [ID] [int] IDENTITY(1,1) NOT NULL, [col1] [nvarchar](50) NULL, [col2] [nvarchar](50) NULL, [col3] [nvarchar](50) NULL, [col4] [nvarchar](50) NULL, [col5] [nvarchar](50) NULL, [col6] [nvarchar](50) NULL) ON [PRIMARY]insert into table_1 (col1,col2,col3,col4,col5,col6) values ('a1','AA','BB','a4','CC','a6')insert into table_1 (col1,col2,col3,col4,col5,col6) values ('b1','b2','b3','b4','b5','b6')insert into table_1 (col1,col2,col3,col4,col5,col6) values ('c1','AA','BB','c4','CC','c6') |
You are subscribed to email updates from SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8) To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment