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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:54:23+00:00 2026-06-16T05:54:23+00:00

I have a table with a unique constraint on two columns. I’m trying to

  • 0

I have a table with a unique constraint on two columns. I’m trying to user on duplicate key update but am getting an error…

… create the table

CREATE TABLE IF NOT EXISTS `requests` (
  `userFrom` int(11) NOT NULL,
  `userTo` int(11) NOT NULL,
  `dateSent` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `userFrom` (`userFrom`,`userTo`)
)

… add some data

INSERT INTO requests (userFrom, userTo) VALUES (1, 2)

… then this fails (when passed userFrom of 1 and userTo of 2

INSERT INTO requests (userFrom, userTo) VALUES (:userFrom, :userTo) ON DUPLICATE KEY UPDATE set dateSent = NOW()

Error is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set dateSent = NOW()' at line 1
  • 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-16T05:54:25+00:00Added an answer on June 16, 2026 at 5:54 am

    i think there is no needed for set keyword here, try this

    INSERT INTO requests (userFrom, userTo) VALUES (:userFrom, :userTo) ON DUPLICATE KEY UPDATE dateSent = NOW()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with two number columns, and a unique constraint over them
I have a database table that has a Unique Key constraint defined to avoid
I have a table in my schema that has a unique constraint on two
Say I have an SQL table that has a unique key (or other) constraint
I have a simple table with two columns, an int identity primary key and
I'm using Hibernate 4.0.1.Final. I have a table with a unique constraint column …
I have a tasks table with a priority column, which has a unique constraint.
I have table with a unique auto-incremental primary key. Over time, entries may be
I have a table with 3 fields: ID (not unique, not primary key) timestamp
I have created the following entity bean, and specified two columns as being unique.

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.