0

I have two tables Token and distinctToken. Following is the description of the two tables.

Token (id int, text varchar(100), utokenid int)

distinctToken (id int, text varchar(100))

The text field in both tables have same data with one exception, that is text field in Token table contains repeated entries.

I wanted to update the Token table such that the utokenid it becomes a foreign key. To be more specific i want to set the value of Token.utokenid = distinctToken.id where Token.text is the same as distinctToken.text. Is it possible using update or should i write a stored procedure to do so.

Imran Ali
  • 2,223
  • 2
  • 28
  • 41

1 Answers1

2
UPDATE Token t, distinctToken dt SET t.utokenid = dt.id WHERE t.text = dt.text;

Am I missing something?

Zds
  • 4,311
  • 2
  • 24
  • 28
  • You are 100% right and missing nothing, I was missing patience as I terminated after 10 minutes each time I ran the same query, mysql took 31 minutes to execute the update. Thank you – Imran Ali Sep 06 '11 at 08:09
  • You can help that by first adding an index to both columns. You can then drop the index after you're done, if needed. – Zds Sep 06 '11 at 08:11