Innovative Thinker
Innovative Thinker

Reputation: 1795

How to Retrieve Data from Two Different MySQL Database using JDBC?

How to retrieve data from two different MySQL database in a single query using jdbc?

SELECT 
      a.`driver_id`,
      a.`state`, 
      a.`lat`, 
      a.`long`, 
      MAX(a.`time_stamp`) AS timestamp,
      b.vehicle_type 
 FROM `rl_driv_location` AS a, `rl_driver_info` AS b 
 WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id` 
       AND b.`vehicle_type` = '"+ cartype +"'  
 GROUP BY driver_id

Upvotes: 0

Views: 238

Answers (1)

Rigel1121
Rigel1121

Reputation: 2016

Just specify the name of the databases where you want to retrieve data. See below.

SELECT 
      a.`driver_id`,
      a.`state`, 
      a.`lat`, 
      a.`long`, 
      MAX(a.`time_stamp`) AS timestamp,
      b.vehicle_type 
 FROM location.`rl_driv_location` AS a, core.`rl_driver_info` AS b 
 WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id` 
       AND b.`vehicle_type` = '"+ cartype +"'  
 GROUP BY driver_id

Upvotes: 1

Related Questions