Reputation: 1795
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
rl_driv_location
table.rl_driver_info
table.Upvotes: 0
Views: 238
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