I've the following code. This code has been in SQL. I want to replicate the same code in R (prefereably dplyr). I found ways to join using inequality conditions but not AND and OR condition. Can someone please guide me?
library(sqldf)
start_date <- c('2022-01-01','2022-02-01','2022-03-01','2022-04-01','2022-05-01','2022-06-01')
end_date <- c('2022-01-31','2022-02-28',NA,NA,'2022-05-31','2022-06-30')
dat1 <- data.frame(start_date, end_date)
date_col <- c('2022-01-15','2022-02-02','2022-03-17','2022-04-22','2022-05-14','2022-06-09')
dat_col <- data.frame(date_col)
final_dat <- sqldf("SELECT * FROM dat_col a LEFT JOIN dat1 b on b.start_date<= a.date_col AND (b.end_date < a.date_col
OR b.end_date IS NULL)")