The code has these problems:
there is actually no nested select at all in the code shown. The statement is requesting all ID's that do not equal the string
'select ID from delete'
. Remove the quotes.delete
is an SQLite keyword. Either use a different name for your data.frame or put the namedelete
in quotes within the SQL statement so it knows not to treat it as a keyword.next time please state the question in a reproducible form. See How to make a great R reproducible example?
Making these three changes we have the following where A has the ID's 1,2,3,4, delete has the IDs 1,2 and B has the ID's 3,4.
library(sqldf)
A <- data.frame(ID = c(1, 1, 2, 3, 4))
delete <- sqldf("select distinct ID from A where ID < 3")
B <- sqldf("select * from A where ID not in (select ID from 'delete')")