I am trying to do a filter query by using the next statement:
SELECT * FROM user_jobs,users WHERE user_jobs.job_title LIKE "%some_keyword%" **OR** user_jobs.job_title LIKE "%another_keyword%" AND user.id=user_jobs.userid
Specs: users.id is PK and user_jobs.userid is FK to users.id
I am trying to filter the users to get the ones that have similar values as specified. When I run it I get a very long loop and finally a large list of users that contains duplicates. (e.g. I only have 300 users and the query shows over 3000 results)
What am I doing wrong, please?
Thanks in advance!
First off, the
ANDoperator holds precedence in this case. Isolate your logic like so:Second of all, don’t use
SELECT * FROM .... This selects all your data, adding network overhead and taking up more time to transfer it all across the server.Reference: https://dev.mysql.com/doc/refman/5.0/en/func-op-summary-ref.html