Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

IT1924

Introduction to SQL (Part II) o Syntax: SELECT columns FROM table_name WHERE
column LIKE pattern;
SQL Data Manipulation Commands o Wildcards: % represents zero, one, or multiple characters
• The basic data manipulation commands are: INSERT, SELECT while _ represents a single character
UPDATE, and DELETE. o Example: SELECT * FROM Students WHERE LastName LIKE
• INSERT INTO – adds new rows/records to a table '_b%';
o Syntax: INSERT INTO table_name (columns) VALUES o Meaning: All students with last names that have 'b' in the
(values); second position.
o Example: INSERT INTO Students (LastName, Section) • IN – an operator used with WHERE to check whether a value matches
VALUES ('Reyes', 'IT102'); any value within a given list
o To add new records to all the columns of a table o Syntax: SELECT columns FROM table_name WHERE
▪ Syntax: INSERT INTO table_name VALUES (values); column IN (values);
▪ Example: INSERT INTO Students VALUES ('Reyes', o Example: SELECT * FROM Students WHERE Section IN
'IT102'); ('IT101', 'IT102', 'IT103');
• SELECT – retrieves values of all rows or a subset of rows in a table • BETWEEN – an operator used with WHERE to check whether a value
o Syntax: SELECT columns FROM table_name; is within a range
o Example: SELECT LastName, Section FROM Students; o Syntax: SELECT columns FROM table_name WHERE
o To select all columns: column BETWEEN value1 AND value2;
▪ Syntax: SELECT * FROM table_name; o Example: SELECT * FROM Students WHERE Age BETWEEN
▪ Example: SELECT * FROM Students; 13 AND 15;
• DISTINCT – an operator used with SELECT to retrieve unique values • ORDER BY – An option used with SELECT to sort retrieved values in
from columns in a table ascending or descending order
o Syntax: SELECT DISTINCT columns FROM table_name; o Syntax: SELECT columns FROM table_name ORDER BY
o Example: SELECT DISTINCT Section FROM Students; columns;
• WHERE – an option used with SELECT to filter the rows of data based o Example: SELECT * FROM STUDENTS ORDER BY
on provided criteria LastName
o Syntax: SELECT columns FROM table_name o To sort values in descending order:
WHERE condition; SELECT * FROM table_name ORDER BY columns DESC;
o Example: SELECT * FROM Students WHERE Section = • UPDATE – modifies existing records in a table
'IT101'; o Syntax: UPDATE table_name SET column1 = value1, …
o To select numeric fields, do not enclose in quotation marks. WHERE condition;
Example: SELECT * FROM Students WHERE Age >= 18; o Example: UPDATE Students SET Section = 'IT202', Status =
• IS NULL – an operator used with SELECT to determine whether a field 'Irregular' WHERE StudentID = '2018-100013';
is empty or not • DELETE – removes existing records in a table
o Syntax: SELECT columns FROM table_name WHERE o Syntax: DELETE FROM table_name WHERE condition;
column IS NULL; o DELETE FROM Students WHERE StudentID = '2018-
o Example: SELECT LastName, Section FROM Students 100013';
WHERE Section IS NULL; o To delete all records: DELETE FROM table_name;
• LIKE – an operator used with WHERE to determine whether a value Reference:
matches a given string pattern Coronel, C. and Morris, S. (2017). Database systems: design, implementation, and management (12th ed.). USA:
Cengage Learning.

07 Handout 1 *Property of ST
 student.feedback@sti.edu Page 1 of 1

You might also like