Toy table: (code to create it in R is given below)
# Source: table<table> [?? x 1]
# Database: sqlite 3.36.0 [:memory:]
text
<chr>
1 blablabla word1 blablabla word2 blablabla
2 blablabla word2 blablabla word1 blablabla
3 blablabla word1 blablabla
QUESTION: Can you help me to write an SQL query using glue_sql() that keeps the rows where text contains both "word1" and "word2", regardless of the order (i.e. rows 1 and 2)?
Something along these lines:
keys <- c("word1", "word2")
q <- glue::glue_sql("SELECT * FROM table WHERE ...", vals = keys, .con = con)
Code to create the table in R:
library(RPostgreSQL)
library(tidyverse)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
table <- data.frame(
text = c("blablabla word1 blablabla word2 blablabla",
"blablabla word2 blablabla word1 blablabla",
"blablabla word1 blablabla"))
dbWriteTable(con, "table", table)
tbl(con, "table")