0% found this document useful (0 votes)
16 views6 pages

Reviewer

Uploaded by

hafajutagana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Reviewer

Uploaded by

hafajutagana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Week 7

Introduction to Database
• Distinct
• Where Clause
• Arithmetic Operators
• Comparison Operators

Data Query Language - It can only access data and cannot manipulate it.
Data Query Language – A limited form of DML (Data Manipulation Language)
Select statements - Can retrieve data from the database.
Select distinct - If there are a lot of similar value and need to fetch the unique value only.

Select Distinct Statement


Select Distinct - Used to retrieve values of all rows that are different from the specified column.
Select Distinct - This will ignore duplicate values on the column and only list the different.

Syntax:

SELECT DISTINCT column1, column2, ...

FROM table_name;

Sample:

SELECT DISTINCT sectionId

FROM tblStudentSection;

If you want to count the number of distinct values, run this command:

SELECT COUNT (DISTINCT sectionId)

FROM tblStudentSection;

Where Clause Statement

Where Clause - Is used to filter the rows that will be displayed.

Where Clause - Using this clause, it will obtain and display all the rows that satisfied the stated condition.
Syntax:

SELECT column1, column2, ...

FROM table_name
WHERE condition;

Sample:

SELECT description

FROM tblItems

WHERE itemName = ‘palmolive’;

Comparison Operator
Operator Description

= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal
!= Not equal

SELECT * FROM tblSales where price <= 5000; (sample)

Arithmetic Operators

Arithmetic Operators - Are used to perform Arithmetic operations on column data.


Operator Description

+ Add
- Subtract
* Multiply
/ Divide
% Modulo

Sample:

SELECT itemName, price * quantity As ‘Total Cost’


FROM tblSales;

WEEK 8-9
Overview of Database Models
• Logical Operators
• Aggregate Functions

AND, OR and NOT Logical


Operators

Logical AND Operator


The AND operator will compare two conditions and display records of a table if both conditions
separated by AND are satisfied or TRUE.

The AND operator can be coded in MySQL either in AND word or && symbols (two ampersand symbols
without space).

Logical OR Operator
The OR operator will compare two conditions and display records of a table if at least ONE condition
separated by OR were satisfied or TRUE.

The OR operator can be coded in MySQL either in OR word or || symbols (two pipe symbols without
space).

Logical NOT Operator


If we want to display rows using a condition that returns NOT TRUE, we may use NOT
Operator.

This operator reverse its Boolean value from the satisfied condition. If the condition is TRUE, it will
reverse into FALSE and if the condition is FALSE, it will be reverse into TRUE instead.

Syntax:

IN and BETWEEN Operators

IN Operator
IN operator is used to search multiple specific values that will match in the set given in WHERE clause.

It is also the shorthand for multiple conditions of OR.

Syntax:

WHERE columnName IN (values);

BETWEEN Operator
The BETWEEN Operator is used to take values on a given range.

Range values can be in number, dates or text.


It is written in inside the CONDITION with word BETWEEN followed by the stating value, followed by AND
word and then followed by ending value.

WHERE price BETWEEN 100 AND 200;

INTRODUCTION TO AGGREGATE FUNCTIONS

Aggregate Functions
This functions can be used in a group of rows to give result of single value. Some examples are
MIN(), MAX(), COUNT(), SUM() and AVG().

Use the MIN() function if you want to get the lowest row value of the chosen column.

Use the MAX() function if you want to get the highest row value of the chosen column.

SELECT MIN(columnName)

SELECT MAX(columnName)

Use the COUNT() function if you want to get the number of rows of selected column.

SELECT COUNT(columnName)

Use the SUM() function if you want to get the summation of all rows of selected numeric column.

SELECT SUM(columnName)

Use the AVG() function if you want to get the average of all rows of selected numeric column.

SELECT AVG(columnName)

WEEK 10-11
Getting Ready to MySQL
• Limit Clause
• Like Operator
• Aliases
• Order by
Limit Clause
The Limit Clause is used to specify the number of retrieved data rows. It is useful on large tables with
more than thousands of rows as retrieving many data will generate poor performance specially when it
is not needed.

LIMIT number;

LIKE Operator
The LIKE Operator is used in a WHERE clause to retrieved specific string pattern.

To produce string pattern, wildcard characters frequently used to signify omitted characters.
• % (percent) symbol signify zero to multiple characters in the result

• _ (underscore) symbol signify one or single character in the result

MySQL Aliases
Aliases is used to give a table or column a temporary name.

It only exists in the query duration.

It is frequently used to make the name of the table or column more readable.

Aliases in tables is useful when there are more than one table used in a query.

Aliases in column is useful when functions in column were used or when two or more columns combined
in a query.

SELECT columnName AS aliasName;

Order By Clause
This Clause is used if you want to sort the data rows result based on specified columns.

It can be in ascending order or descending.

It can be applied to column on any data type such varchar, integer, double, date, etc.

You might also like