MySQL join with like or and statements?

Hi folks please help me.

JOIN
left join data l on (l.entityId = u.id)

How can I add like statement to the join above.

json LIKE \'%'.$parametername.'%\' or address LIKE \'%'.$parametername.'%\'

what table do the json and address columns come from?

if it’s the data table, then you would write –

  FROM users u
LEFT 
  JOIN data l 
    ON l.entityId = u.id
   AND ( l.json LIKE '%'.$parametername.'%' 
      OR l.address LIKE '%'.$parametername.'%'
       )

but if it’s another table, you would write –

  FROM users u
LEFT 
  JOIN data l 
    ON l.entityId = u.id
 WHERE ( x.json LIKE '%'.$parametername.'%' 
      OR x.address LIKE '%'.$parametername.'%'
       )

Out of curiousity, is the same-table(s)-AND due to optimization? Because you COULD do the same tables with the where condition too…

you could…

… but the left join would then effectively be an inner join, which is ~not~ the same thing

1 Like