Learning PHP and SQL on an online MOOC, this is a homework that I've got to do.

I need to write a query in SQL to count all the services which involve a particular person in my database.

The particular's name is Gary Crowley located in the 'staff' table. Below is my table: 'staff' table in main database

My question is: What is the actual SQL query I should write to get the exact count of all the services which involve Gary Crowley? As you can see in the picture, the name appears four times. I have written a query that output the services only involving Gary Crowley but I don't know how to make the COUNT query.

  • Which DBMS are you using? – a_horse_with_no_name May 11 '16 at 11:08
  • Installed WampServer, PHPMyAdmin – user94348 May 12 '16 at 3:48
select count(distinct service_id)
from staff
where staff_firstname = 'Gary'
  and staff_surname = 'Crowley';

The distinct is only necessary if your database design allows to assign the same service multiple times to the same staff member.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy