Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using sub query. Sub query A query inside another query.

Similar presentations


Presentation on theme: "Using sub query. Sub query A query inside another query."— Presentation transcript:

1 Using sub query

2 Sub query A query inside another query

3 Examples of Subqueries

4 Example 1 Retrieve the name of all employees who have dependents

5 Example 1(continued) In this example: the sub query is used in the where clause. The example goal: to retrieve the ssn for the employees who have at least one dependent.

6 Example 2 Retrieve the name of all employees who works on two projects

7 Example 2 In this example: the sub query is used in the having clause The example goal: to retrieve the number of projects for each employee who works on at least one project in the works_on table.

8 Example 3 Retrieve the name of all employees with the department name each employee works on.

9 Example 3 In this example: the sub query is used in the select clause. The example goal: to retrieve the name of the department that each employee works on.

10 Example 4 Retrieve all employees who works on all projects

11 Example 5 Update the location of all projects controlled by Headquarter department to be in New york Before updateAfter update

12 Example 6 Delete all employees in works_on table who works on all the projects located in Belliare After delete Before delete

13 Backup and restore a database

14 Backup a database Step 1

15 Backup a database Step 2: click ok to backup The location for the backed up database

16 Restore a database Step 1:

17 Restore a database Step 2: choose from device

18 Restore a database Step 3: add the database backup you want to restore

19 Restore a database Step 4: choose the location of the database backup you want to restore.

20 Restore a database Step 5: Now press OK for the last two interfaces Check the check box Choose your database

21 Restore a database Step 6: add the red colored text before the database location to correct the location of the database C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\clinic.mdf C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\clinic_1.LDF

22 Restore a database Step 7: Now your database created successfully The restored database


Download ppt "Using sub query. Sub query A query inside another query."

Similar presentations


Ads by Google