Reviewer
Reviewer
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.
Syntax:
FROM table_name;
Sample:
FROM tblStudentSection;
If you want to count the number of distinct values, run this command:
FROM tblStudentSection;
Where Clause - Using this clause, it will obtain and display all the rows that satisfied the stated condition.
Syntax:
FROM table_name
WHERE condition;
Sample:
SELECT description
FROM tblItems
Comparison Operator
Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal
!= Not equal
Arithmetic Operators
+ Add
- Subtract
* Multiply
/ Divide
% Modulo
Sample:
WEEK 8-9
Overview of Database Models
• Logical Operators
• Aggregate Functions
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).
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 Operator
IN operator is used to search multiple specific values that will match in the set given in WHERE clause.
Syntax:
BETWEEN Operator
The BETWEEN Operator is used to take values on a given range.
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
MySQL Aliases
Aliases is used to give a table or column a temporary name.
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.
Order By Clause
This Clause is used if you want to sort the data rows result based on specified columns.
It can be applied to column on any data type such varchar, integer, double, date, etc.