Lab 5
Lab 5
LAB-5
Objectives
- Understand COUNT() function in SQL.
- Understand (ORDER BY) keyword in SQL.
- Understand (AND & OR) operators in SQL.
- Understand (NOT) operator in SQL.
- Understand (IS NULL & IS NOT NULL) operators in SQL.
COUNT Function:
This function will count the items in the selected column,
ORDER BY:
The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
SELECT * FROM table_name
ORDER BY column1 ASC, column2 DESC;
The AND operator is used to filter records based on more than one condition.
The WHERE clause can contain one or many AND operators.
The AND operator displays a record if all the conditions are TRUE.
The OR operator displays a record if any of the conditions are TRUE.
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
LAB WORK
Here are the SQL commands to create and fill the table:
INSERT INTO Students (student_id, name, age, grade, major, email, scholarship) VALUES
(1, 'Alice', 20, 'A', 'Computer Science', '[email protected]', TRUE),
(2, 'Bob', 22, 'B', 'Engineering', NULL, FALSE),
(3, 'Charlie', 19, 'A', 'Mathematics', '[email protected]', TRUE),
(4, 'David', 21, 'C', 'Physics', '[email protected]', FALSE),
(5, 'Eva', 20, 'B', 'Biology', NULL, TRUE),
(6, 'Frank', 23, 'D', 'Chemistry', '[email protected]', FALSE),
(7, 'Grace', 21, 'A', 'Computer Science', '[email protected]', TRUE),
(8, 'Hannah', 19, 'B', 'Engineering', '[email protected]', TRUE),
(9, 'Isaac', 22, 'C', 'Mathematics', NULL, FALSE),
(10, 'Judy', 20, 'A', 'Physics', '[email protected]', TRUE);