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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:59:52+00:00 2026-06-09T19:59:52+00:00

I’ve been trying for a few hours (probably more than I needed to) to

  • 0

I’ve been trying for a few hours (probably more than I needed to) to figure out the best way to write an update sql query that will dissallow duplicates on the column I am updating.

Meaning, if TableA.ColA already has a name ‘TEST1’, then when I’m changing another record, then I simply can’t pick a value for ColA to be ‘TEST1’.

It’s pretty easy to simply just separate the query into a select, and use a server layer code that would allow conditional logic:

SELECT ID, NAME FROM TABLEA WHERE NAME = 'TEST1'

IF TableA.recordcount > 0 then
    UPDATE SET NAME = 'TEST1' WHERE ID = 1234
END IF

But I’m more interested to see if these two queries can be combined into a single query.

I am using Oracle to figure things out, but I’d love to see a SQL Server query as well. I figured a MERGE statement can work, but for obvious reasons you can’t have the clause:

..etc.. WHEN NOT MATCHED UPDATE SET ..etc.. WHERE ID = 1234

AND you can’t update a column if it’s mentioned in the join (oracle limitation but not limited to SQL Server)

ALSO, I know you can put a constraint on a column that prevents duplicate values, but I’d be interested to see if there is such a query that can do this without using constraint.

Here is an example start-up attempt on my end just to see what I can come up with (explanations on it failed is not necessary):

ERROR: ORA-01732: data manipulation operation not legal on this view

UPDATE (
    SELECT d.NAME, ch.NAME FROM (
        SELECT 'test1' AS NAME, '2722' AS ID
        FROM DUAL
    ) d
    LEFT JOIN TABLEA a
    ON UPPER(a.name) = UPPER(d.name)
)
SET a.name = 'test2'
WHERE a.name is null and a.id = d.id

I have tried merge, but just gave up thinking it’s not possible. I’ve also considered not exists (but I’d have to be careful since I might accidentally update every other record that doesn’t match a criteria)

  • 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-09T19:59:53+00:00Added an answer on June 9, 2026 at 7:59 pm

    It should be straightforward:

    update personnel
    set personnel_number = 'xyz'
    where person_id = 1001
    and not exists (select * from personnel where personnel_number = 'xyz');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this

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.