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 9076405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:06:06+00:00 2026-06-16T19:06:06+00:00

I have a table that looks similar to this… +————-+————-+ | Field | Type

  • 0

I have a table that looks similar to this…

+-------------+-------------+
| Field       | Type        |
+-------------+-------------+
| var1        | varchar(15) |
| var2        | varchar(25) |
| var3        | int(1)      |
+-------------+-------------+

The issue is that I need to be able to insert the 3 variables, but only if var1 and var2 aren’t already in the table. If var1 and var2 are already in the table, var3 should be updated.

So for example

INSERT INTO table (var1, var2, var3) VALUES('0','1','2')

Would insert the 3 values, but

INSERT INTO table (var1, var2, var3) VALUES('0','1','1')

Would update (‘0′,’1′,’2’) to be (‘0′,’1′,’1’)

The important thing is that if var1 and var2 exist, a duplicate entry with a different var3 is not entered.

I’ve looked around at a few other questions, but most of them seem to recommend IGNORE which I don’t think will work for me since I’m checking for multiple duplicates.

  • 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-16T19:06:07+00:00Added an answer on June 16, 2026 at 7:06 pm

    First, set (var1,var2) as combined PRIMARY KEY

    ALTER TABLE table ADD PRIMARY KEY(var1,var2)
    

    Then use INSERT ON DUPLICATE UPDATE

    INSERT INTO table (var1, var2, var3) VALUES ('0','1','2') ON DUPLICATE KEY UPDATE var3 = '2'
    
    • 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 looks like this: ID (pk,int) Col1 (nvarchar) Col2 (nvarchar)
I have a table that looks like this: ------------------------------------------------------------------- CUSTNUM (INT), ITEMNUM (INT), MONTH
I have some data in a table that looks similar to this: Item Date
I have a table that looks similar to this: rule_id parent_id 1 0 2
I have a report table that looks similar to this reports inspection_type | inspection_number
I have a table within Access that looks similar to this: ProductID - ClientID
I have a NodeSet of a table that looks similar to this: <table cellpadding=1
I have a table with contents that look similar to this: id | title
I have a large reporting table in Excel that looks similar to the following.
I have a table that looks like this: id value AGA 0.211 AGA 0.433

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.