0% found this document useful (0 votes)
55 views

SQL Basics

This document provides an overview of SQL basics covered in Week 12, including writing SQL statements, using the ORDER BY statement to sort results, and joining tables. It discusses compound conditions with AND, OR and NOT operators. It also demonstrates the ORDER BY keyword to sort query results in ascending or descending order and explains how to perform inner joins to match rows from different tables using foreign keys.

Uploaded by

Jai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

SQL Basics

This document provides an overview of SQL basics covered in Week 12, including writing SQL statements, using the ORDER BY statement to sort results, and joining tables. It discusses compound conditions with AND, OR and NOT operators. It also demonstrates the ORDER BY keyword to sort query results in ascending or descending order and explains how to perform inner joins to match rows from different tables using foreign keys.

Uploaded by

Jai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

WEEK 12

SQL BASICS
Week 12: SQL Basics

Course Learning Outcomes:


 Learn how to write SQL statement and know the result of a given SQL statement

 Learn how to use ORDER BY statement

 Learn how join tables


Week 12: SQL Basics

DATABASE QUERIES
Week 12: SQL Basics

COMPOUND CONDITIONS
Compound Conditions use logical operators to filter or connect multiple criteria.

The WHERE clause can be combined with AND, OR, and NOT operators.
Week 12: SQL Basics

AND OPERATOR
AND operator displays a record if all the conditions separated by AND are TRUE.
 
AND Syntax
 
SELECT [ Column(s), or other expression]
FROM [Table(s)]
[WHERE condition 1 AND condition 2 AND condition 3 …:]
 
AND Examples
 
SELECT *
FROM Products
WHERE Price <= 20 AND Price >=10;
Week 12: SQL Basics

OR OPERATOR
OR operator displays a record if any of the conditions separated by OR is TRUE.

OR Syntax

SELECT [ Column(s), or other expression]


FROM [Table(s)]
[WHERE condition 1 OR condition 2 OR condition 3 …:]
 
OR Examples
 
SELECT *
FROM Products
WHERE ShippedDate = ‘8/2/1996’ OR ShippedDate = ‘8/3/1996’:
Week 12: SQL Basics

ORDER BY KEYWORD
Used to sort the result. Sorts the records in ascending order by default.
To sort the records in descending order, use the DESC keyword.

ORDER BY Syntax
 
SELECT [ Column(s), or other expression]
FROM [Table(s)]
[ORDER BY column 1, column 2, … ASC/DESC;]
 
 
ORDER BY Examples

SELECT *
FROM Customers
ORDER BY Country;
Week 12: SQL Basics

TABLE JOIN
Table join use to retrieve data from multiple tables. The query result consists of columns from more
than one table.

To match rows from different table we will use two (2) Join.
Cross Join – NO need to match
Inner Join – Used the foreign key as the matching criteria
Week 12: SQL Basics
Week 12: SQL Basics

TABLE JOIN EXAMPLES


Week 12: SQL Basics

TABLE JOIN ALTERNATIVE

You might also like