Welcome to WebmasterWorld Guest from 54.81.78.135

Forum Moderators: open

Message Too Old, No Replies

MySQL: SET array()

Is this even possible?

     
1:20 am on Feb 24, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 713
votes: 58


Let's say that I have this:

@var_user = 'user_1';

INSERT INTO tableA
SELECT username, columnA FROM tableB
WHERE username=@var_user;


That's just a sample code, so please forgive any typos or glaring errors.

But now, I want to insert, say, 50 lines, with 50 different usernames. I know I could write a PHP script for it, but it would be a lot easier if I could just copy and paste a code into PMA.

I'm hoping that something exists like:

@var_user_array = (
'user_1',
'user_2',
'user_3',
...
'user_50'
);

INSERT INTO tableA
SELECT username, columnA FROM tableB
WHERE username=@var_user_array;


or maybe something like this:

@var_user_array = (
'user_1',
'user_2',
'user_3',
...
'user_50'
);

FOREACH @var_user (@var_user_array) {
INSERT INTO tableA
SELECT username, columnA FROM tableB
WHERE username=@var_user;
}


I've been searching Google and can't find anything like that, but I know I'm not the first person to wish for it.

Can you guys suggest anything other than writing a PHP script for it?
9:09 am on Feb 24, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3377
votes: 41


can you not do this:

INSERT INTO tableA
SELECT username, columnA FROM tableB
WHERE username IN ('user_1','user_2','user_3');
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members