1

How can I send query that joining tables from two different databases with RMySQL:: dbSendQuery?

with SQL:

select * from mydb1.table as A left join mydb2.table as B on A.id=B.id

With R:

get_db1_data <- RMySQL::dbSendQuery(mydb1,"SELECT * FROM table")

get_db2_data <- RMySQL::dbSendQuery(mydb2,"SELECT * FROM table")

How can I combine these two lines of code to one with RMySQL::dbSendQuery?

MKR
  • 19,739
  • 4
  • 23
  • 33
Sharedobe
  • 135
  • 1
  • 9
  • if there is no dblink, you prob cant do that. why dont you join it in R using dplyr or data.table? see also https://stackoverflow.com/questions/1565993/oracle-database-link-mysql-equivalent – chinsoon12 Apr 06 '18 at 22:52
  • Possible duplicate of https://stackoverflow.com/q/2132654/3358272 – r2evans Apr 06 '18 at 23:59
  • 1
    Three more things: I think you should be using `DBI::` functions, not `RMySQL` functions directly; [you should use `dbGetQuery`](https://github.com/r-dbi/DBI/blob/2bcb77d03ab52c8fd14ff76af1087a8b12dcbd25/R/DBConnection.R#L76-L81) instead of `dbSendQuery` (unless you know you need it); and you may want to consider [`RMariaDB`](https://cran.r-project.org/web/packages/RMariaDB/index.html), as `RMySQL` itself suggests [on CRAN](https://cran.r-project.org/web/packages/RMySQL/index.html). – r2evans Apr 07 '18 at 00:29

0 Answers0