You are on page 1of 15

Session 3

Overview of SQL Server and


Transact SQL

KolenSoft
Session Objectives
 Define query
 Use SELECT statement with different clauses
 Define filtering
 Explain horizontal and vertical filtering
 List wildcard characters, relational operators
and logical operators
 Describe FROM, WHERE clauses
 Define ORDER BY clause
 Define system global variables

KolenSoft
SELECT Statement

Columns
required
Table names
Condition
Other clauses

Used to retrieve rows and columns


KolanSoft inc
SELECT syntax and examples (1)

KolenSoft
SELECT syntax and examples (2)

KolenSoft
SELECT syntax and examples (3)

KolenSoft
SELECT syntax and examples (4)

KolenSoft
Filtering
Empno Ename Sal Deptno
2222 Allen 2000 20
3333 Brian 3000 30
4444 Derek 4000 40
5555 Cathy 3500 10
7777 Fred 3700 20
8888 Greg 4300 30

KolenSoft
Horizontal Filtering (1)

Achieved by using:
 ‘WHERE’ Clause

 Relational Operators

 Logical Operators

 Wildcard Characters

 ‘ORDER BY’ clause

KolenSoft
Relational Operators
Operator Meaning
= Equal To
> Greater Than
< Less than

>= Greater Than or Equal To

<= Less Than or Equal To

! Not
KolenSoft
Horizontal Filtering (2)
Wildcard Description Example

‘_’ A single character Select Branch_Code From Branch


Where Branch_Code Like ‘L__’

% A string of any length Select Route_Code From


FlightSchedule Where Route_Code
Like ‘AMS-%’

[] A single character within the range Select Airbusno From


enclosed in the brackets FlightSchedule Where Airbusno
Like ‘AB0[1-5]’

[^] Any single character not within the Select Airbusno From
range enclosed in the brackets FlightSchedule Where Airbusno
Like ‘AB0[^1-5]’

KolenSoft
Logical Operators

 And : SELECT COUNT(empno) as “Number of emp"


FROM emp WHERE deptno = 30 and
job=‘SALESMAN’

 Or : SELECT * FROM emp WHERE job =


‘ANALYST’ OR job = ‘CLERK’

 Not : SELECT * FROM emp WHERE NOT deptno = 10


KolenSoft
ORDER BY clause

KolenSoft
System Global Variables(1)

KolenSoft
System Global Variables(2)

KolenSoft

You might also like