SQL Query Help

I'm trying to build a SQL query for my PHP code that will count & display the number of assignments from data within my MySQL database. I only need to display & count  the active and the ones locaed in office2. Below is my SQL query but it is displaying & counting all workers:

$query="SELECT worker, active, COUNT(worker) FROM psrinfo WHERE location = 'office2' AND active = '1'  ";


I have a total of 10 workers. I only need to display worker1, worker2, worker3, worker4, worker6 and worker8.

At this time it counts all workers 1 - 10
LVL 15
wantabe2Asked:
Who is Participating?
 
cfEngineersConnect With a Mentor Commented:
 select count(*)
    from psrinfo
 where location = 'office2'
    AND active = '1'
    AND worker IN ('worker1','worker6')

0
 
cfEngineersCommented:
take the COUNT(worker) out and paste your results.

0
 
wantabe2Author Commented:
okay, if I can get the below to work, it will fix my issue.

Instead of writing a fancy SQL can I just pick & choose what I need the SQL to pull out & count? If I remove AND worker = 'worker6' it displays & counts the number of assignments for worker1 but when I add it it displays nothing.... At this time I only need it to count the number of times it see's worker1 & worker 6 in the worker field & ignore the others...
$query="SELECT worker, active, COUNT(worker) FROM psrinfo WHERE location = 'office2' AND active = '1' AND worker = 'worker1' AND worker = 'worker6' ";

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.