Solved

Set value where duplicated column value.

Posted on 2014-02-19
7
252 Views
Last Modified: 2014-02-25
I want to set the SUFFIX column to the value of the ID column if the value of the URL occurs more than once

For example in this case...
URL		SUFFIX	ID
/test.html	Null	1
/test.html	Null	2
/test.html	Null	3

Open in new window


...as the URL exists more than once then the Suffix should be set to the ID for each entry
0
Comment
Question by:Gary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 4

Expert Comment

by:ravikantninave
ID: 39870914
update TableName set suffix=id Where url in (select url from testmast group by url having count(*) > 1);
0
 
LVL 58

Author Comment

by:Gary
ID: 39870928
That gives
Error in query (1093): You can't specify target table 'url' for update in FROM clause
0
 
LVL 58

Author Comment

by:Gary
ID: 39873649
I've requested that this question be deleted for the following reason:

Solved it with

UPDATE url t1
  JOIN
  (
    SELECT url_id,url
      FROM url
     GROUP BY url
    HAVING COUNT(*) > 5
  ) t2
  ON t1.url= t2.url
  SET t1.suffix= t1.id;
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 8

Expert Comment

by:Surrano
ID: 39872792
Please don't delete the question. Give this "solved with" comment as a new author comment and accept it as a solution instead. This will give everyone 0 points (same as deletion) but the knowledge will remain searchable in EE.
0
 
LVL 58

Accepted Solution

by:
Gary earned 0 total points
ID: 39873646
UPDATE url t1 
  JOIN
  (
    SELECT url_id,url
      FROM url
     GROUP BY url
    HAVING COUNT(*) > 5
  ) t2
  ON t1.url= t2.url
  SET t1.suffix= t1.id;

Open in new window

0
 
LVL 58

Author Comment

by:Gary
ID: 39873650
Solved myself
0
 
LVL 58

Author Closing Comment

by:Gary
ID: 39885115
Solved myself
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question