1

I'm trying to compare subject IDs between columns to find unique IDs. I keep on getting a syntax error even though I've spent the past hour checking and re-checking my syntax. I decided to make a simple data frame to play around with an low and behold I get the same error.

Here my syntax for the proxy data frame

color <- c('yellow', 'red', 'green', 'blue') 
number <- c(1,3,4,5) 
stuff <- data.frame(color, number) 

sqldf('select number, from stuff where color = red')

Here's the error I got

Error in sqliteSendQuery(con, statement, bind.data) : error in statement: near "from": syntax error

I'm beyond frustrated that I can't get this simple query to work. What gives? I even tried removing the comma before 'from' and then I get the following error.

Error in sqliteSendQuery(con, statement, bind.data) : error in statement: no such column: red

6
  • a comma after number , in the query Commented Mar 24, 2016 at 17:25
  • tried removing that and I got the second error about no column called red existing, which is true. but that shouldn't matter since i explicitly stated I wanted it to look in the column 'color' Commented Mar 24, 2016 at 17:28
  • surround either side of red with quotes. I did not see that before. 'red' Commented Mar 24, 2016 at 17:29
  • You didn't put red in quotes. Use double quotes for the query, single quotes for things in the query that need to be quoted. Commented Mar 24, 2016 at 17:29
  • 1
    Since it's clear you don't understand SQL that well, why don't you use base R subsetting and whatnot? Commented Mar 24, 2016 at 17:32

1 Answer 1

3

Remove commas and change quotes:

> stuff
   color number
1 yellow      1
2    red      3
3  green      4
4   blue      5

> sqldf("select number from stuff where color = 'red'")
  number
1      3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.