Yet another JOIN question

Hey,

I have two tables and one search field, and of course I’d like to search both tables: comment in A table and comment and title in B table.

I have this code:

SELECT DISTINCT
    p.id
  , p.date
  , p.project_ID
  , p.provider_ID
  , p.timeframe
  , p.budget
  , p.comment
FROM
 rq_production AS p

  INNER JOIN (
  SELECT
      id
    , title
    , comment
  FROM
   rq_jobs
  ) AS j
  
  ON p.comment LIKE '%" . $_POST['sort_keyword'] . "%' || j.title LIKE '%" . $_POST['sort_keyword'] . "%' || j.comment LIKE '%" . $_POST['sort_keyword'] . "%' && p.project_ID = j.id
   
  ORDER BY date DESC

which, surprisingly to meself :), kinda works.

Kind of, because for certain words it spits out in the result rows that surely DON’T have such word in neither title nor comment.

Looking at the code, could you tell me where did I make a mistake?
Much appreciated!

Thanks,
Greg

PS.
I cannot see the top portion of my post, for some reason.

Hey,

I have two tables and one search field, and of course I’d like to search both tables: comment in A table and comment and title in B table.

I have this code:
which, surprisingly to meself :), kinda works.

Kind of, because for certain words it spits out in the result rows that surely DON’T have such word in neither title nor comment.

Looking at the code, could you tell me where did I make a mistake?

Thanks again,
Greg

your problem is with operator precedence

Presumably you want


(condition or condition or condition) and condition

You shouldn’t use ||/&& instead of or/and since those are not standard sql and hence will not work with another DBMS