943,876 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 532
  • MySQL RSS
Jul 6th, 2009
0

Compare a column's value

Expand Post »
Hi all,

I have a table in which i have 2 columns.i.e. name and ID number as

Table1
--------------------------
Name || ID number
--------------------------
Mark || 204
Roger || 207
Ronny || 209
Robert || 309
mac || 390
black ||
Mark ||
Roger ||
Mac ||
Mark ||
Ronny ||
black || 409

I want to do a query on column 'Name' and where ever i find same name, i want to to insert the same ID number into the corresponding ID number. i.e output should be as:
Table1
--------------------------
Name || ID number
--------------------------
Mark || 204
Roger || 207
Ronny || 209
Robert || 309
mac || 390
black || 409
Mark || 204
Roger || 207
Mac || 390
Mark || 204
Ronny || 209
black || 409

I tried implementing this as:

UPDATE Table1 SET Table1.IDnumber = Table1.IDnumber WHERE Table1.Name LIKE Table1.Name;

But it does not do anything and gives the original table as the output.
I tried it by using 2 tables as well,by creating a duplicate table Table2 of Table1 and then putting a query on Table1.Name as:

UPDATE Table1, Table2 SET Table1.IDnumber=Table2.IDnumber WHERE Table1.Name LIKE Table2.Name;

But in this case also, i dont get the desired output. It shows the same original table only.
Please help...
Thanking you,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
me8042 is offline Offline
3 posts
since Jun 2009
Jul 7th, 2009
0

Re: Compare a column's value

Quote ...
i want to to insert the same ID number into the corresponding ID number..
Use insert query.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: self-referential relationship help please.
Next Thread in MySQL Forum Timeline: How to Build a database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC