Imran Ali
Imran Ali

Reputation: 2279

How to update column in one table from another if both tables have a text field in common

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.

Upvotes: 0

Views: 143

Answers (1)

Zds
Zds

Reputation: 4359

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

Am I missing something?

Upvotes: 2

Related Questions