Solved

Set value where duplicated column value.

Posted on 2014-02-19
7
246 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
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://…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

18 Experts available now in Live!

Get 1:1 Help Now