Search code examples
sqlrleft-joinsqldf

Why did sqldf in R give this syntax error?


I tried package sqldf in R. I tried a very easy join. However, I got this syntax error.

library(sqldf)

radius1 <- sqldf("select radius.*, all.height, all.bmi
                  from radius left join all
                  on radius.uID = all.study_id
                 ")

Error: near "all": syntax error

What is wrong?


Solution

  • As neilfws has rightly pointed out; all is a reserved keyword in SQL queries and so is the syntax error.

    If you still want to use "all" table name; you can surround it using backticks as below :

    library(sqldf)
    
    radius1 <- sqldf("select radius.*, `all`.height, `all`.bmi
                      from radius left join `all`
                      on radius.uID = `all`.study_id
                     ")