Introduction To SQL
Introduction To SQL
TO SQL - ACCESS
U. Rangith
ICTT – Instructor | NVQ Level – 04
Vocational Training Center
Ministry of Vocational Training Authority of Sri Lanka
There are Four Main Parts
■ SELECT
■ FROM
■ WHERE
■ ORDER BY
Access SQL – Programming with
Access 2007
■ SELECT Statement
– Return value from a specify field in a table or tables
■ Fully Qualified:
– SELECT employee.ID, employee.FirstName, employee.LastName,
employee.UserName
Selecting Field From Table to Display
■ SELECT Statement
– Return value from a specify field in a table or tables
■ Fully Qualified:
SELECT Table1. FieldName1, Table1. FieldName2, Table1. FieldName3, Table1.
FieldName4
FROM Table1;
SELECT Query Example
■ Fully Qualified:
– SELECT employee.ID, employee.FirstName, employee.LastName,
employee.UserName
■ SELECT *
FROM Employee;
INNER JOIN
Return all record were given values are equal in both tables.
Usage
FROM Customers INNER JOIN Contacts ON
Customer.ID=Contacts.Customer_ID
OUTER JOIN
Return records from one table and some records from another table where given values are equal in
both tables.
Usage
FROM Customers LEFT JOIN Contacts ON Customer.ID=Contacts.Customer_ID
All SOME
FROM Customers RIGHT JOIN Contacts ON Customer.ID=Contacts.Customer_ID
SOME ALL
Full Use
Example:
Example:
Example:
SELECT COUNT(Field_Name)
FROM Table_Name;
Example:
SELECT COUNT(sname)
FROM sailor;
Using And, OR Functions
ORDER BY This is used to Order Change the Ascending Order of particular Field Name
Example:
Example:
■ The MIN() function returns the smallest value of the selected column.
■ The MAX() function returns the largest value of the selected column.
MIN() Syntax
SELECT MIN(Field_Name)
FROM Table_Name
WHERE condition;
Example
SELECT MIN(Student_Average)
FROM Stu_Marks
Where Condition;
The SQL MIN() and MAX() Functions
■ The MIN() function returns the smallest value of the selected column.
■ The MAX() function returns the largest value of the selected column.
MAX() Syntax
SELECT MAX(Field_Name)
FROM Table_Name
WHERE condition;
Example
SELECT MAX(Student_Average)
FROM Stu_Marks
Where Condition;
The SQL BETWEEN Operator
■ The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates.
■ The BETWEEN operator is inclusive: begin and end values are included.
SELECT Field_Name1,
FROM Table_Name
WHERE Field_Name BETWEEN value1 AND value2;
Example:
Example: