0% found this document useful (0 votes)
23 views23 pages

SQL Class 3 Slide-1

The document discusses SQL concepts like filtering grouped data using the HAVING clause, creating and altering tables, performing different types of joins, set operators like UNION and UNION ALL, and using the CASE expression for conditional logic.

Uploaded by

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

SQL Class 3 Slide-1

The document discusses SQL concepts like filtering grouped data using the HAVING clause, creating and altering tables, performing different types of joins, set operators like UNION and UNION ALL, and using the CASE expression for conditional logic.

Uploaded by

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

MODULE 5: LESSON 3

SQL - Junior High


Don't be result obsessed , Enjoy the procees
What's your Learning Intention
FILTERING GROUPED DATA
HAVING CLAUSE

HAVING always comes after a Group by statement or for filtering aggregated values. Whereas a where clause filters
individual records, the Having the clause filters grouped records

SELECT category, SUM(quantity) AS total_quantity


FROM Orders
GROUP BY category
HAVING SUM(quantity) > 100;
TABLES
CREATE

INSERT

ALTER

UPDATE

DELETE
CREATE TABLE table_name ( CREATE TABLE users (
column1 datatype [constraints], id INT PRIMARY KEY,
column2 datatype [constraints], username VARCHAR(50) NOT NULL,
... email VARCHAR(100) UNIQUE,
columnN datatype [constraints] age INT,
); created_at DATE DEFAULT GETDATE());

Replace table_name with the name you want to give to the new table. In the
parentheses, define the columns of the table, each with its respective datatype and
optional constraints. The datatype represents the type of data the column can store,
such as INT, VARCHAR, DATE, etc. The constraints are optional and specify rules or
restrictions on the data in the column, like NOT NULL, PRIMARY KEY, UNIQUE,
DEFAULT, etc.
JOINS
INNER JOIN - Multiple Joins & Joining on multiple keys

OUTER JOIN

LEFT OUTER JOIN


RIGHT OUTER JOIN
FULL OUTER JOIN

CROSS JOIN
INNER JOIN
LEFT JOIN
SET OPERATOR
UNION & UNION ALL
The UNION operator is used to combine the results of two or more SELECT queries into a
single result set. It removes duplicates from the combined result set, meaning that it
returns only distinct rows.
Note: UNION ALL returns duplicates

SELECT column1 AS alias, column2, ...


FROM table1
WHERE condition1
UNION
SELECT column1, column2, ...
FROM table2
Set operations do not require a field to join ON. This is because they
don't quite do the same thing as JOIN operators rather than comparing
& merging tables on the left and right, they stack fields on top of one
another
CASE
The CASE expression allows you to perform conditional logic within a SQL query. It
is used to return different values based on specified conditions.

SELECT ProductName, Price,


CASE
WHEN Price >= 1000 THEN 'Expensive' CASE
WHEN condition1 THEN result1
WHEN Price >= 500 THEN 'Moderate' WHEN condition2 THEN result2
...
ELSE 'Affordable' ELSE default_result
END AS PriceCategory END

FROM Products;

You might also like