Solved

Set value where duplicated column value.

Posted on 2014-02-19
7
249 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Creating and Managing Databases with phpMyAdmin in cPanel.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now