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

  • SEARCH
  • Home
  • 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 7711583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:24:46+00:00 2026-06-01T01:24:46+00:00

Before inserting data into table i need to check against duplicate records and report

  • 0

Before inserting data into table i need to check against duplicate records and report list of those records.
Query should not insert anything while there is at least one duplicate.

Number of records to insert: ~1000

Rows in table: ~1.000.000

Table:

CREATE TABLE `test` (
  `A` varchar(19) NOT NULL,
  `B` varchar(9) NOT NULL,
  KEY `A` (`A`),
  KEY `B` (`B`)
) ENGINE=InnoDB;

I need to check for both columns:

What is the efficient way of doing this.

Thanks in advance.

P.S. consider using php and mysql

  • 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-01T01:24:47+00:00Added an answer on June 1, 2026 at 1:24 am

    Say duplicate means a username already exists. so you can try:

    1] use a for loop to group all usernames that’s in your insert list: pseudo code follows:

      $names="";
      for(each element){
          $names.=$val.", ";
      //remove last comma ","
    

    Then use following sql statement to get all duplicate entries.

      select * from myTable where username in ($names);
    

    having obtained a list of all your duplicates, then insert as

    insert into myTable (username, address, otherstuff)
    values("henry", "35 skid", "who knows")
    ON DUPLICATE KEY UPDATE 
    otherstuff = values(otherstuff);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable which I need to strip of sybols before inserting into
Is pg_escape_string or mysql_escape_string enough to sanitize a string before inserting data into a
I am inserting data into a table by selecting from another table which may
I want to validate the data contained by Value Objects before inserting into the
DetailsView1.DefaultMode = DetailsViewMode.Insert; After inserting how can i Preview Data before Submitting/Inserting data in
I have to insert the values in the table named First, but before inserting
hie all, i want to insert the data into the table only if the
How can I check if a field exists in a table. I need an
I am inserting rows into a table from a Powershell script. I loop through
I really need help with filling in data in a Table View, where my

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.