Вы находитесь на странице: 1из 22

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name : K.Chandra Sekhar
Designation : Associate Lecturer
Branch : DCCP
Institute : Central Institute of Commerce,Tarnaka,
Hyd.
Year/Semester : V Semester
Subject : Relational Database Management System
Subject Code : CCP-505
Topic : Know the components of SQL
Duration : 50 Minutes
Sub-Topic : Write statements using the SQL Commands
Teaching Aids : PPT,Animation, Photographs
CCP505.39TO40 1
OBJECTIVES

On Completion of this period, you would


be able to know :

• How to write statements using the SQL Commands.

• Examples for Various SQL Commands.

CCP505.39TO40 2
Recap
 Uses of SQL commands with examples

CCP505.39TO40 3
Data Base Name : STUDENT Table Name : STD_PER_DETAILS

Table 1
CCP505.39TO40 4
Data Base Name : STUDENT Table Name : STD_RESULTS

Table 2
CCP505.39TO40 5
Structure of STUDENT Database Tables

Table Name : STD_PER_DETAILS

Field Name Data Type Size


admsn_no Number 5
rank Number 5
std_name Varchar2 20
f_name Varchar2 20
sex Char 1
DOB Date
cat Char 2
region Char 4

Table 3
CCP505.39TO40 6
Structure of STUDENT Database Tables

Table Name : STD_RESULTS

Field Name Data Type Size


rollno Number 5
pin Char 20
std_name Varchar2 20
sub1mark Number 3
sub2mark Number 3
sub3mark Number 3
sub4mark Number 3
sub5mark Number 3

Table 4
CCP505.39TO40 7
Selecting all Columns of a Table

 SQL>SELECT * FROM STD_PER_DETAILS;

 SQL>SELECT * FROM STD_RESULTS;

CCP505.39TO40 8
Selecting Specific Columns from a Table

 SQL>SELECT admsn_no, rank, std_name

FROM STD_PER_DETAILS;

 SQL>SELECT pin, std_name

FROM STD_RESULTS;

CCP505.39TO40 9
To eliminate duplicate Rows in the Result

 SQL>SELECT DISTINCT region

FROM STD_PER_DETAILS;

 SQL>SELECT DISTINCT std_name

FROM STD_RESULTS;

CCP505.39TO40 10
Selecting Specific Rows from a Table

SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS WHERE rank <=2000;

SQL>SELECT std_name

FROM STD_RESULTS WHERE Sub5mark <=50;

CCP505.39TO40 11
Controlling the Order of displayed Rows

SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS WHERE rank <=2000

ORDER BY Ascending ;

SQL>SELECT std_name

FROM STD_RESULTS WHERE Sub5mark <=50

ORDER BY descending ;
CCP505.39TO40 12
Selecting Rows with in the Range
SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS WHERE

rank BETWEEN 500 AND 1000;

CCP505.39TO40 13
Selecting Rows from the list of values

SQL>SELECT std_name

FROM STD_PER_DETAILS

WHERE cat IN (‘SC’,’BC’) ;

CCP505.39TO40 14
Selecting Rows with Character pattern
match
 Lists all the rows where student name starts
with K

 SQL>SELECT rank, std_name,cat,region


FROM STD_PER_DETAILS
WHERE std_name LIKE K% ;

CCP505.39TO40 15
Selecting Rows using compound
expressions

SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS

WHERE rank < 2000 AND cat = ‘BC’ ;

CCP505.39TO40 16
Selecting Rows using compound
expressions

SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS

WHERE cat = ‘SC’ OR cat = ‘BC’ ;

CCP505.39TO40 17
Selecting Rows using compound
expressions

SQL>SELECT rank, std_name,f_name

FROM STD_PER_DETAILS

WHERE region != ‘OU’ ;

CCP505.39TO40 18
Summary

 Uses of SELECT command with different examples


like
 Pattern searching
 Arranging in order
 Eliminating duplicate entries , etc.,

CCP505.39TO40 19
Quiz
1. For eliminating duplicate record (rows) along with
‘select’ the following clause is used
 Duplicate
 Distinct
 Original
 None of the above

Answer is : Distinct

CCP505.39TO40 20
Frequently asked questions

1. Explain with syntax the uses of SELECT command


2. Write an example for the following
a) Display all records in the table
b) Display all records beginning the name with
character ‘s’

CCP505.39TO40 21
Assignment

Write a Query to Display Ename’s with the Designation


DGM.

Write a Query to Display Products with Price <10 and in


Ascending Order.

Write a Query to list Different Products .

CCP505.39TO40 22

Вам также может понравиться