Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
PHP searching from fixed rows

I have patient table with 1000+ patient records. All records are created by 5 admins. I have separated patients in patient table using admin_id column. When admin "A" login then he only can see those patient that created by him. Now i wanna search patient from patient table. My search result will be only form patient records those are created by admin "A";

MySQL query:

SELECT 
    *
FROM
    patient
WHERE
    admin_id = 36 AND fname LIKE '%test%'
        OR email LIKE '%test%'
        OR mobile LIKE '%test%'
ORDER BY ID DESC 

(Here I get result from all records but I need only from where admin_id = 36.)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You have to put around the OR close a parentheses () so that the expression only is true when admin_id is 36 and the rest also is true

SELECT 
    *
FROM
    patient
WHERE
    admin_id = 36 AND (fname LIKE '%test%'
        OR email LIKE '%test%'
        OR mobile LIKE '%test%')
ORDER BY ID DESC 
over 4 years ago · Santiago Trujillo Report

0

Try:-

SELECT 
    *
FROM
    patient
WHERE
    (admin_id = 36 AND fname LIKE '%test%')
        OR (email LIKE '%test%')
        OR (mobile LIKE '%test%')
ORDER BY ID DESC 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!