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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:19:26+00:00 2026-06-11T21:19:26+00:00

I am running a insert statement to insert data, but I want to check

  • 0

I am running a insert statement to insert data, but I want to check for any duplicate entries based on date and then do an entry.

All I want is if today a user enters product_name='x', ‘x’ is unique so that no one can enter product name x again today. But of course the next day they can.

I do not want to run a select before the insert to do the checking. Is there an alternative?

  • 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-11T21:19:27+00:00Added an answer on June 11, 2026 at 9:19 pm

    You can use the mysql insert into... on duplicate update syntax which will basically enter in a new row if one isn’t there, or if the new row would have caused a key constraint to kick in, then it can be used to update instead.

    Lets say you have the following table:

    MyTable
    ID | Name
    1  | Fluffeh
    2  | Bobby
    3  | Tables
    

    And ID is set as the primary key in the database (meaning it CANNOT have two rows with the same value in it) you would normally try to insert like this:

    insert into myTable 
        values (1, 'Fluffster');
    

    But this would generate an error as there is already a row with ID of 1 in it.

    By using the insert on duplicate update the query now looks like this:

    insert into myTable 
        values (1, 'Fluffster') 
        on duplicate key update Name='Fluffster';
    

    Now, rather than returning an error, it updates the row with the new name instead.

    Edit: You can add a unique index across two columns with the following syntax:

    ALTER TABLE myTable
    ADD UNIQUE INDEX (ID, `name`);
    

    This will now let you use the syntax above to insert rows while having the same ID as other rows, but only if the name is different – or in your case, add the constraint on the varchar and date fields.

    Lastly, please do add this sort of information into your question to start with, would have saved everyone a bit of time 🙂

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

Sidebar

Related Questions

i want to insert all processes that running into listbox, and also how to
So I'm trying to do a simple insert using Linq but i'm running into
Is there any way to stop a running loop inside another method or insert
I have 30 tables of data that I'm running a query on, and then
I have a problem running an insert query via C# OleDbCommand to an Access
I'm running a pretty standard INSERT INTO [table] (col1, col2, ...coln) select * from
I'm running SQL Server 2005 Express. And I'm trying to do a bulk insert/import
Consider a web page having grid-view connected to SqlDataSource having all permission to insert
I am attempting to insert data into a local SQLITE database file from a
Is there a Mysql statement which provides full details of any other open connection

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.