PDA

View Full Version : mass update of users Help...


lemarsu
04-04-2003, 02:18 PM
I need to do a mass update of users based on some field in different tables

I have written some SQL but it would not work under mysql (in the office DB2 and oracle are ok with this kind of sql)

This is what I am trying to run :

UPDATE user,userfield
SET user.usergroupid=8
WHERE
userfield.userid=user.userid AND
userfield.field8= 'United Kingdom' AND
user.usergroupid='5'


Can anyone please help....

Thanks
LeMarsu

Xenon
04-04-2003, 02:27 PM
hmm i don't know the update command very well, but maybe this will work:

UPDATE user LEFT JOIN userfield USING(userid) SET usergroupid=8 WHERE field8='United Kingodm' AND usergroupid=5

lemarsu
04-04-2003, 03:41 PM
that doesn't work as well !!

There is something in myphp I don't get ! I can only do simple update Queries !

I don't know where I read this but apparently you can do updates with joins in mySQL ... can that be true !!?

LeMarsu ... need HELP !!!

mr e
04-04-2003, 04:11 PM
when it doesn't work, what happens? if you just copied xenons query exactly it had a spelling error at Kindom

lemarsu
04-04-2003, 05:17 PM
this is the error I get :

Error
SQL-query :

UPDATE
user
LEFT JOIN
userfield
USING(userid)
SET usergroupid=8
WHERE field8='United Kingdom' AND usergroupid=5


MySQL said:


You have an error in your SQL syntax near 'LEFT JOIN
userfield
USING(userid)
SET usergroupid=8
WHERE field8='United ' at line 3

lemarsu
04-06-2003, 09:32 AM
I found this posts on the web...
http://www.geocrawler.com/archives/3/8/1999/3/0/1441850/


You can`t do a join in an update (or delete) statement. So you
have to select the rows you want to update in one query, then
join the selected IDs into a string separated by commas, then
update WHERE iparty_sku IN (<string of selected IDs>).

Xenon
04-06-2003, 10:49 AM
that means you have to write a script which selects u the rows to update at first:


<?php
require('./global.php');
$users=$DB_site->query("SELECT user.userid FROM user LEFT JOIN userfield USING (userid) WHERE user.usergroupid=5 AND userfield.field8='United Kingdom'");
$userids = '(0';
while($user=$DB_site->fetch_array($users)) {
$userids .= ','.$user['userid'];
}
$userids .= ')';
$DB_site->query('UPDATE user SET usergroupid=8 WHERE userid IN '.$userids);

?>