CRUD Statements  «Prev  Next»

Create a DELETE Statement using a Subquery - Exercise

Create a DELETE statement using a subquery

Objective: Practice creating a DELETE statement using a subquery.

Exercise scoring


This exercise is worth a total of 5 points. You will receive up to 5 points for accurately creating the DELETE statement as described in the instructions.

Instructions

To test your understanding of the relationship between subqueries and joins, use the same instructions as the prior exercise, but construct a subquery instead of selecting values from another table. To review the instructions, use the course project as an example. Remember the Timesheets table looks like this:

EmployeeID

ClientID

TaskID WeekEndingDate Hours
1171016/1/9930
1171026/8/9950
231016/15/9940
3321036/1/9945
3321036/8/9935


The Tasks table looks like this:
TaskID Description Chargeable
101Vacation0
102General1
103Programming1

The task is to delete all employees from the Timesheets table for tasks that are not chargeable, as listed in the Tasks table. Construct a DELETE statement that uses a subquery from the Tasks table to retrieve the values to be deleted. Do not use a join.
Hint: You need to use an IN statement in the WHERE clause.

Submitting the exercise

Type or paste your Transact-SQL statement into the text box below, then click Submit to submit the answer and view a results page.