Friday, February 17, 2012

doing a distinct insert?

hi there,

i was just wondering if it's possible to do a INSERT INTO, but with a DISTINCT on three columns at ones?

i want to insert values from a SELECT DISTINCT column_1, column_2, column_3 FROM table

thanks

SJB

Is this what you want to do?

INSERT newTab (col1, col2, col3)
SELECT DISTINCT col1, col2, col3 FROM otherTab

This works just fine.

/Kenneth

|||

yes

if i understand your ideea , this is the scenario:

I have 2 similar tables :

CREATE TABLE [dbo].[person](

[last] [nvarchar](50) NULL,

[first] [nvarchar](50) NULL,

[age] [nvarchar](50) NULL

) ON [PRIMARY]

CREATE TABLE [dbo].[person](

[last] [nvarchar](50) NULL,

[first] [nvarchar](50) NULL,

[age] [nvarchar](50) NULL

) ON [PRIMARY]

person have 3 rows with 2 duplicates

insert into person1

select distinct last,first,age

from person

insert only 2 rows

No comments:

Post a Comment