I have a dataframe in R which contains the output of previous queries. Unfortunately, I cannot do this directly in SQL since it is too slow so I am using the data.table package. The output from the data.table package is a data frame of 50,000 ids. I need to pull all records from the database for each id.
# x is a dataframe containing 50,000 ids.
Usually, I would do something like,
dbGetQuery(con, "Select * from data where id in x")
but that won't work. An alternative is to do 50,000 queries in a for loop, but I am thinking that there must be a more efficient method to do this.
What is the most efficient way to do this?