Internal join on LIKE sqldf

How can I use a clause LIKEwith an inner join using sqldf in R?

Code:

Name <- c("Jack","Jill","Romeo")
Name <- as.data.frame(Name)
FullName <- c("School Jack H", "School Juliet G", "College Jill M", "College Romeo F")
Marks <- c("100","82","54","0")
FullBio <- cbind(FullName, Marks)
FullBio <-as.data.frame(FullBio)

And then when I ran:

sqldf("select a.*, b.* from Name a join FullBio b on a.Name like '%'+b.[FullName]+'%'") 

returns 0 rows.

Why? What are my other alternatives, please. I apologize for creating so many variables to run my code.

+4
source share
1 answer

The string concatenation operator ||in SQLite:

sqldf("select * from Name join FullBio on FullName like '%' || Name || '%'")

giving:

   Name        FullName Marks
1  Jack   School Jack H   100
2  Jill  College Jill M    54
3 Romeo College Romeo F     0

Any of these will also work:

sqldf("select * from Name join FullBio on instr(FullName, Name)")

sqldf("select * from Name join FullBio on like('%' || Name || '%', FullName)")
+4
source

Source: https://habr.com/ru/post/1620528/


All Articles