Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:19:28+00:00 2026-06-06T13:19:28+00:00

I have a table that has duplicate email address, I need to insert just

  • 0

I have a table that has duplicate email address, I need to insert just one of them into a temp a temp table along with two other fields. there are many example here but I can get any of them work,

I ended up looking into MERGE I get the same results. All the record are getting inserted I’m at a lost. I tried many different samples but it always insert all the records. I went back to make sure the email address are really dupes and they are.. Below is were I’m at now..

MERGE #EmailTable2 AS Target
USING (SELECT EMAIL, NAME, JOB_TITLE FROM b2b_cmas_list$ WHERE EMAIL IS NOT NULL) AS Source
ON (Target.EMAIL = Source.EMAIL)
 WHEN NOT MATCHED BY TARGET THEN
    INSERT (EMAIL, NAME, JOB_TITLE)
    VALUES (Source.EMAIL, Source.NAME, Source.JOB_TITLE)

OUTPUT $action, inserted.*, deleted.*;

so any help in getting this correct would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:19:29+00:00Added an answer on June 6, 2026 at 1:19 pm

    This it not working because SQL doesn’t know, which of the two rows containing the same e-mail you want to choose. I mean: if EMAIL is the same, which of pair (NAME and JOB_TITLE) are important and which can be discarded?

    Some hints:

    1. If it doesn’t matter which item is chosen simply group by EMAIL selecting MAX(NAME) and MAX(JOB_TITLE), i.e.

      select EMAIL, max(NAME), max(JOB_TITLE) from b2b_cmas_list$ group by EMAIL

      Be warned however that this can mangle NAME-JOB_TITLE pairs (as max is selected).

    2. Try using ROW_NUMBER() OVER() to arbitrarilly select 1st row in each group.

    3. Use a CURSOR to iterate over rows and skip duplicates.

    4. Use .NET CLR aggregate to i.e. concat names and job titles for same e-mail.

    And a little note to your MERGE statement. This is not working as expected, because SQL checks all rows at once, and not row-by-row. So it is not that if one e-mail. ie. “a@a.com” is inserted, then another won’t. It only matters if “a@a.com” is in the table at the beginning of the statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has duplicate data for the same user_id. I need
I have one table that has sales records and another table that has additional
I currently have a customers table that has duplicate customers in it. I want
I have a table that has multiple duplicate records as the following: ID Title
So I have this temp table that has structure like: col1 col2 col3 col3
I have an Event database loaded into Core Data that has duplicate Event titles.
I have an MSSQL 2000 table that has a lot of duplicate entries. Each
I have a table in my database which has duplicate records that I want
I Have an ASP:Table that has a row with cells in I need to
I have a table that has an AUTO_INCREMENT field. Currently, it is also a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.