PDA

View Full Version : SQL Query : Mass move specific users based on usernames, not userid


flyguye
04-05-2012, 09:21 AM
Hi,

I need to mass move specific users (a couple of hundred of them) based on their usernames, not based on their id, to be deleted at a later time.

Each user is unique, with differing post counts, join dates, etc.

I've tried to mess around with some SQL queries but no luck.


UPDATE user
SET usergroupid = X
WHERE user = adam john mike etc

I have the usernames on excel so if I could add them into the query either comma separated, or space separated, or line separated would be great! :up:

I've no knowledge on SQL, so I might be shootin' in the dark here! :confused:

Pandemikk
04-05-2012, 09:24 AM
UPDATE user
SET usergroupid = X
WHERE username IN('Apostrophe is important', 'etc')

Only problem is you have to make sure the username's are escaped. Feel free to PM me a list of the username's and I'll write up a quick script that'll get the job done.

flyguye
04-05-2012, 09:49 AM
Very kind of you sir! However the list isn't finalized yet, will PM you the list once it's finalized!

However, I don't understand what you mean by the usernames being escaped?

--------------- Added 1333624292 at 1333624292 ---------------

Managed to do it!

I used excel to add the 'apostrophes' and appropriate spaces at the end of each username, and pasted it in the following format:


UPDATE user
SET usergroupid = X
WHERE username IN(
'adam',
'john',
'mike'
)

Where X is the target usergroupid

That allowed me to paste the all the usernames at one go!

Thanks again! :up: SOLVED!

Pandemikk
04-05-2012, 01:17 PM
By escaped, I mean there are certain characters in usernames that would break the query, most notably an apostrophe itself. But seeing as how everything worked out I'm going to assume none of the username's had an apostrophe in them, anyway. ;)

Glad I could be of assistance. :D