tags:

views:

206

answers:

2

I am confused about how to copy a column from one table to another table using where. I wrote SQL query but it says transaction lock time exceeded or query returns more than one row.
using mysql
Basically,
I have:

Table 1:  Results
BuildID  platform_to_insert

Table 2:  build
BuildID correct_platform

update results set results.platform_to_insert 
     = (select correct_platform from  
       build where results.BuildID = build.BuildID)
+1  A: 

There are two options here:

  1. update your tables to use BuildID as a primary key (to avoid duplicates)
  2. update your subquery to only return one result

    UPDATE results SET results.platform_to_insert = (SELECT correct_platform FROM build WHERE results.BuildID=build.BuildID LIMIT 1);

tmpvar
I want to update all the rows in results
JPro
the problem is that the WHERE clause is matching multiple elements in the subquery. This can be solved by limiting the subquery's result set to one or making *.BuildID a primary key to avoid duplicates in the first place.In either case all of the rows will be updated.
tmpvar
A: 

I do not believe you need a sub query.

UPDATE results, build
SET    results.platform_to_insert = build.correct_platform
WHERE  results.BuildID = build.BuildID
Benoit Vidis