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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -