Solved

Set value where duplicated column value.

Posted on 2014-02-19
7
250 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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.
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…

810 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