View Single Post

   
  #3 (permalink)  
Old 02-27-2008, 09:18 PM
Jerry Stuckle
 
Posts: n/a
Default Re: query question: updating between 2 tables

Peter Van Dijck wrote:
> Hi all,
> trying to figure out if there is a query I can use for this, or if I
> have to write a php script to loop tru each row...
>
> table1:
> entryid int(11)
> itemid int(11)
>
> table2:
> object_id int(11)
> ....
>
> The situation is: table2.objectid is populated with the values of
> table1.itemid, but they have to be replaced with the corresponding
> table1.entryid.
>
> I could do in PHP:
> - select * from table2
> - for each row, update table2 with select from table1
>
> but I am wondering if there is 1 query that could take care of this?
>
> Peter
>
>
>


If there is no overlap between table1.entryid and table1.itemid values,
you can do:

UPDATE table2 SET object_id = table1.entryid WHERE table2.object_id =
table1.itemid

If there is an overlap in values, you're safer doing a short script to
retrieve all rows and update accordingly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote