Experiment 07
Aim
To demonstrate the use of various DML operations i.e., SELECT statement, WHERE clause, AND, OR, NOT operators, ORDER BY, and INSERT SELECT statement
Theory
-
SELECT statement:
The
SELECTstatement is used to retrieve data from a database. It allows the user to specify which columns to retrieve and from which table.SyntaxSELECT column1, column2, ...
FROM table_name;To select all columns from a table:
SyntaxSELECT * FROM table_name; -
WHERE clause:
The
WHEREclause is used to filter records that meet a certain condition. It is used in conjunction with theSELECT,UPDATE,DELETE, etc. statements.SyntaxSELECT * FROM table_name
WHERE condition; -
AND, OR, NOT operators:
The
AND,OR, andNOToperators are used to combine multiple conditions in aWHEREclause.SyntaxSELECT * FROM table_name
WHERE condition1 AND condition2;
SELECT * FROM table_name
WHERE condition1 OR condition2;
SELECT * FROM table_name
WHERE NOT condition; -
ORDER BY clause:
The
ORDER BYclause is used to sort the result set in either ascending (ASC) or descending (DESC) order.SyntaxSELECT * FROM table_name
ORDER BY column_name ASC|DESC; -
INSERT SELECT statement:
The
INSERT SELECTstatement is used to insert new records into a table by selecting data from another table.SyntaxINSERT INTO table_name (column1, column2, ...)
SELECT column1, column2, ...
FROM another_table
WHERE condition;
Commands
SELECT * FROM Employees; -- Draw the table "Before Insertion"
WHERE Age > 30 AND Department = 'HR'
ORDER BY LastName ASC;
INSERT INTO Employees (EmployeeID, FirstName, LastName, Age, Department)
SELECT EmployeeID, FirstName, LastName, Age, Department
FROM AnotherEmployees
WHERE Age > 25;
SELECT * FROM Employees; -- Draw the table "After Insertion"
Conclusion
Successfully implemented SELECT statement, WHERE clause, AND, OR, NOT operators, ORDER BY clause, and INSERT SELECT statement (DML) commands