Solved

Set value where duplicated column value.

Posted on 2014-02-19
7
253 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
Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 
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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Creating and Managing Databases with phpMyAdmin in cPanel.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

728 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