database - Use different MySQL databse based on condition -


i have 2 identical databases different names. want create universal sql both. database name , use table that. can that?

code:

select @db := database();  select   *   @db.table1 t1 inner join   @db.table2 t2 on t2.id = t1.table2_id; 

thanks in advance...

the following should work you:

select @db := database(); select @stmt:= concat('select   * `', @db, '`.table1 t1 inner join   `', @db, '`.table2 t2 on t2.id = t1.table2_id'); prepare stmt @stmt; execute stmt; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -