Introduction To Database: UCT - Mogadishu, Somalia

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Introduction to Database

UCT – Mogadishu, Somalia


Introduction to SQL

Simple Queries
Introduction to SQL

 Select Query

 Select * from Loan;

 Select LCID,LDate,LReturn from Loan;


Introduction to SQL

 Where Clause
 Where clause is used to specify condition while retriving
data from table. Where clause is used mostly with
Select, Update and Delete query. If condititon specified
by where clause is true then only the result from table is
returned

 Select * from Loan WhereLReturn = '2017-04-06'


;
Introduction to SQL

 Where Clause
In addition to the equal sign , The WHERE clause can contain other
comparison operators including :
<> ( or !=)
>
<
>=
<=
!>
!<
Introduction to SQL

 Boolean Operators
 Multiple conditions can be built using Boolean operators
AND , OR , and NOT

Select * from Mps Where MPGender = ‘F’ AND MPClan =300;

Select * from Mps Where MPGender = ‘F’ OR MPClan =300;

Select Distinct * from Mps Where MPGender = ‘F’ OR MPClan =300;

Boolean Expression Priorities

1.Not

2.And

3.Or
Introduction to SQL

 IN and BETWEEN Operators


 An IN operator allows the specification of two or more expressions to be used for a
query.

Select * from MPS where MPClan in (100,300,500);


Select * from MPS where MPClan = 100
or MPClan = 300
or MPClan = 500
 The IN operator can be used with Logical operator NOT

Select * from MPS where MPClan NOT in (100,300,500);


Introduction to SQL

 IN and BETWEEN Operators


 The BETWEEN operator searches for all values in the range inclusively
 Qualifying values can be between or equal to lower and upper
boundary values
Select * from MPS where MPClan Between 200 and 400;

Select * from MPS where MPClan >= 200 AND MP<= 400;

Select * from MPS where MPClan NOT Between 200 and 400;
Introduction to SQL

 Queries involving Null Values


 A null in the create table or alter table specifies that a special
value called NULL(which usually represents unknown values)

SELECT * FROM CANDIDATE WHERE CanProfile is null;

SELECT * FROM CANDIDATE WHERE CanProfile is not null;

SELECT CanName,isNull(CanProfile,'Taariikh Ma laha') from


CANDIDATE;
Introduction to SQL

 Like Operator
 Like is an operator that compares column values with
specified pattern.
The general form of LIKE operator is
column [NOT] LIKE ‘pattern’

 Certain characters within the pattern – called wild card


characters – have specific interpretation

 Two of them are


 % - Specifies any sequence of zero or more characters
 _ - Specifies any single character
Introduction to SQL

 Like Operator

 SELECT * FROM CANDIDATE WHERE CANNAME LIKE 'H%';

 SELECT * FROM CANDIDATE WHERE CANNAME LIKE '_H%';

You might also like