質問

Here is the nested query i am using:

insert into ( select dbtable from profiles where ( email = 'blah@test.com' ) ) values ( null, null, 'blah@test.com', 'testing' )

the tablename will be fetched by the SELECT query for the INSERT query to run but i am getting this #1064 error.

I get another error of "#1103 - Incorrect table name" if i use back-ticks like this:

insert into `( select dbtable from profiles where ( email = 'blah@test.com' ) )` values ( null, null, 'blah@test.com', 'testing' )

I tried and searched for this but still i am stuck here. Can anybody help?

Sorry if this is an easy question as i am a newbie in this.

役に立ちましたか?

解決

select dbtable from profiles where ( email = 'blah@test.com' ) into @tableName;
set @queryy = CONCAT(CONCAT('INSERT INTO ', @tableName), ' values ( null, null, \'blah@test.com\', \'testing\' )');

prepare myQuery from @queryy;
execute myQuery;
deallocate prepare myQuery;

I think it should help you solve your problem.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top