mysql - SQL Insert Into multiple rows, but execute subquery only once -



mysql - SQL Insert Into multiple rows, but execute subquery only once -

im trying optimize insert statement utilize subquery once, same value:

heres illustration code

insert table1 (id, number) values ((select other_id table2 somevalue = "test"), 12), ((select other_id table2 somevalue = "test"), 13), ..., ...;

not sql-expert, doesnt approach, same subquery gets executed on every insert.

is there alternative solution?

also, know can select id beforehand , store in variable (pseudo-code-like):

$var = mysql_query("select other_id table2 somevalue = 'test'") mysql_query("insert table1 (id, number) values ($var, 12), ($var, 13);")

insert table1 (id, number) select other_id, number table2 cross bring together ( select 12 number union select 13 ) q somevalue = 'test'

mysql sql subquery insert-into

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -