update table1 from table with duplicates
I have 2 tables:
NewTable (partNumber, html)
OldTable(partNumer, html)
The old table has duplicate data i.e. rows with the same partNumber and html.
NewTable is empty.
I want to take the rows from 'OldTable' and insert them into NewTable.
The only condition that I get any row from 'OldTable' where the html column is not an empty string, so:
SELECT TOP 1 FROM OldTable WHE开发者_Python百科RE html <> ''
What would the update look like?
This should work:
INSERT INTO NewTable(partNumber, html)
SELECT DISTINCT partNumber, html FROM OldTable WHERE html <> ''
Put a unique index on the NewTable including partNumber and html then turn on Ignore dups.
Then you can simply...
INSERT NewTable(partNumber, html) SELECT OldTable partNumer, html WHERE html <> ''
精彩评论