'My query runs perfectly in SQL but when trying to retrieve the query data from R studio, it says syntax error in line 1 of query code. How can I fix?

Is there something wrong with my query code here? Or is it a user issue with my computer and/or programs?

Here is the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SQL_assignment.sql' at line 1 [1064]

Here is SQL code

USE sakila;
select CONCAT(first_name , " ", last_name  ) as Actor_Name, count(rental_id) as Rental_Count
from actor 
inner join FILM_ACTOR
using (actor_id)
inner join FILM
using (FILM_ID)
inner join inventory
using (FILM_ID)
inner join Rental 
using (inventory_id)
group by Actor_Name
order by count(rental_id) desc

Here is R code (R can connect to SQL via user, password, host id, etc)

x <- dbSendQuery(mydb, "SQL_assignment")
data <- dbFetch(x)


Solution 1:[1]

The 2nd argument to dbSendQuery should be SQL statement. You are passing it a string. For example:

dbSendQuery(conn, "SELECT * FROM table")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Robert Long