Hi all,
Due to the lack of "WHERE IN" for joins, I'm trying to add a bracketed 'OR WHERE' query, but I can't find the right way.
I need to do the following: Join Table T2 to Table T1, where ( T2.x = T1.y) and (T2.z in (1,2,3,4)). The best I got so far is
Join T2 on T2.x = T1.y and T2.z = 1 or T2.z = 2 or T2.z = 3 ..... but this is not a good solution as I need it bracketed, like: Join T2 on T2.x = T1.y and (T2.z = 1 or T2.z = 2 or T2.z = 3)
Also, something interesting, is that if I use:
$join->on("T2.x", "=", T1.y") ->where('T2.z', "IN", DB::raw("('1', '2')")); })
I get a MySQL error (SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;). However, If I copy/paste the query it provides as faulty to MySQL client - it works!! :-(
Appreciate your help, I'm stuck with this for a day now :-(
try to replace
DB::raw("('1', '2')")
with
DB::raw("(1, 2)")
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community