Database has a table A, and a table B. A.ID is linked with B.ID.
I need to update all instances of A.Name to be equal to B.Catalog, if and only if those instances are linked A.ID = B.ID.
Only entries in A where A.Owner = 0 should be updated.
The code I have come up with is:
UPDATE A
SET A.Name = (SELECT B.Catalog
FROM B, A
WHERE (B.ID = A.ID) AND (A.Owner = 0))
WHERE A.ID IN (SELECT B.ID
FROM B, A
WHERE (B.ID = A.ID) AND (A.Owner = 0))
The error is "Subquery returned more than one value" (MS SQL 2005 adds "MSG 512, LEVEL 16, STATE 1, LINE 1"). I understand what the error is telling me, that I am trying to set a single value to be equal to the multiple results returned by the SELECT statement, but I think my knowledge of SQL is too lacking to come up with the proper code.
Any help would be greatly appreciated. This is what I get for trying to teach myself! A headache!
1 Answer