• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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
0
wantabe2
Asked:
wantabe2
  • 2
1 Solution
 
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
 
cfEngineersCommented:
 select count(*)
    from psrinfo
 where location = 'office2'
    AND active = '1'
    AND worker IN ('worker1','worker6')

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now