+ All Categories
Home > Documents > Using sub query. Sub query A query inside another query.

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

Date post: 13-Jan-2016
Category:
Upload: griselda-fowler
View: 282 times
Download: 1 times
Share this document with a friend
Popular Tags:
22
Using sub query
Transcript
Page 1: Using sub query. Sub query A query inside another query.

Using sub query

Page 2: Using sub query. Sub query A query inside another query.

Sub queryA query inside another query

Page 3: Using sub query. Sub query A query inside another query.

Examples of Subqueries

Page 4: Using sub query. Sub query A query inside another query.

Example 1

Retrieve the name of all employees who have dependents

Page 5: Using sub query. Sub query A query inside another query.

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.

Page 6: Using sub query. Sub query A query inside another query.

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

Page 7: Using sub query. Sub query A query inside another query.

Example 2In 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.

Page 8: Using sub query. Sub query A query inside another query.

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

Page 9: Using sub query. Sub query A query inside another query.

Example 3In 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.

Page 10: Using sub query. Sub query A query inside another query.

Example 4Retrieve all employees who works on all projects

Page 11: Using sub query. Sub query A query inside another query.

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

Before update After update

Page 12: Using sub query. Sub query A query inside another query.

Example 6Delete all employees in works_on table who works on all the projects located in Belliare

After deleteBefore delete

Page 13: Using sub query. Sub query A query inside another query.

Backup and restore a database

Page 14: Using sub query. Sub query A query inside another query.

Backup a databaseStep 1

Page 15: Using sub query. Sub query A query inside another query.

Backup a databaseStep 2: click ok to backup

The location for the backed up database

Page 16: Using sub query. Sub query A query inside another query.

Restore a databaseStep 1:

Page 17: Using sub query. Sub query A query inside another query.

Restore a databaseStep 2: choose from device

Page 18: Using sub query. Sub query A query inside another query.

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

Page 19: Using sub query. Sub query A query inside another query.

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

Page 20: Using sub query. Sub query A query inside another query.

Restore a databaseStep 5: Now press OK for the last two interfaces

Check the check box

Choose your database

Page 21: Using sub query. Sub query A query inside another query.

Restore a databaseStep 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

Page 22: Using sub query. Sub query A query inside another query.

Restore a databaseStep 7: Now your database created successfully

The restored database


Recommended