![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I have a table (Main) with compound key and second, temporary table (Temp) with same fields but without PK. Main table key is 3 columns ( SourceFileHash, FileHash, PathHash ). There is also 4 other columns in each table. My intent is to use temp table to store batches of records with duplicates and inserting only unique records to main table after every batch is finished ( batches are inserted using SqlBulkCopy ). How can I select distinct records on Temp table but using only 3 PK columns ? Here is query that I created - it won't work because it is trying to insert duplicate records to main: SELECT temp.sourceFileHash, temp.pathHash, temp.fileHash, temp. [length], temp.creationDate, temp.modificationDate, temp.lastAccessDate, temp.line FROM CatalogEntriesTemp temp LEFT OUTER JOIN CatalogEntries main ON main.pathHash = temp.pathHash and main.fileHash = temp.fileHash AND main.sourceFileHash = temp.sourceFileHash WHERE main.pathHash IS NULL AND main.fileHash IS NULL AND main.sourceFileHash is null Thanks for any help in advance. |
#3
| |||
| |||
|
|
Hello, I have a table (Main) with compound key and second, temporary table (Temp) with same fields but without PK. Main table key is 3 columns ( SourceFileHash, FileHash, PathHash ). There is also 4 other columns in each table. My intent is to use temp table to store batches of records with duplicates and inserting only unique records to main table after every batch is finished ( batches are inserted using SqlBulkCopy ). How can I select distinct records on Temp table but using only 3 PK columns ? Here is query that I created - it won't work because it is trying to insert duplicate records to main: SELECT temp.sourceFileHash, temp.pathHash, temp.fileHash, temp. [length], temp.creationDate, temp.modificationDate, temp.lastAccessDate, temp.line * * * * * * * * FROM CatalogEntriesTemp temp * * * * * * * * LEFT OUTER JOIN CatalogEntries main ON main.pathHash = temp.pathHash and main.fileHash = temp.fileHash AND main.sourceFileHash = temp.sourceFileHash * * * * * * * * WHERE main.pathHash IS NULL AND main.fileHash IS NULL AND main.sourceFileHash is null Thanks for any help in advance. |
#4
| |||
| |||
|
|
I have a table (Main) with compound key and second, temporary table (Temp) with same fields but without PK. Main table key is 3 columns ( SourceFileHash, FileHash, PathHash ). There is also 4 other columns in each table. My intent is to use temp table to store batches of records with duplicates and inserting only unique records to main table after every batch is finished ( batches are inserted using SqlBulkCopy ). How can I select distinct records on Temp table but using only 3 PK columns ? Here is query that I created - it won't work because it is trying to insert duplicate records to main: |
#5
| |||
| |||
|
|
You need to fill in the ORDER BY clause to determine which of the rows with the same duplicate key you want. |
![]() |
| Thread Tools | |
| Display Modes | |
| |