Help to build a query in Mysql - Build a query between two tables, each table is in a different database

Asked

Viewed 7 times

-1

Gentlemen good afternoon

I am a junior programmer, and I came across a situation in the company , which I can not solve , what happens , we need to compare two values , but each value is in a different database, it is a percentage calculation , in which we will verify the percentage of the value and make a check

For example

Database : A -> Battery Table

Database : B -> Table Monit

we need to take the value field of the battery table of the "A" database and compare it with the "STRAIN" field of the "B" database Monit table"

I even made a query , but with all tables on the same basis

but or so

select value,

CASE WHEN ((VALUE / SELECT TENSAO FROM MONIT WHERE ID= ID_CLIENTE) *100)> 80 AND (VALUE / SELECT TENSAO FROM MONIT WHERE ID= ID_CLIENTE)<100

THEN "IT’S ALL RIGHT"

WHEN ((VALUE / SELECT TENSAO FROM MONIT WHERE ID= ID_CLIENTE) *100)> 40 AND (VALUE / SELECT TENSAO FROM MONIT WHERE ID= ID_CLIENTE)<60

THEN "IN STATE OF CARE"

END THE SITUATION

FROM BATTERIES WHERE ID_CLIENTE = 1

It would be more or less like this , but in the above case the two tables are in the same database , but we need to assemble this query , considering that the two tables , will be in different databases , it is possible to do this in php , creating a new instance , using the Lockable, but I need help

Thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.