Dbms Module3 Chapter1
Dbms Module3 Chapter1
divided into different categories based on the type of operations that can be
performed on the data. These categories include DDL, DML, DCL, TCL, and DQL.
CREATE TABLE Employees (
EmployeeID INT PRIMARY
KEY,
Name VARCHAR(100),
Department
VARCHAR(50)
);
SQL supports a range of data types across widely used classes of data,
such as the following:
Numeric types
String or character types
Temporal types for dates and times
INSERT INTO Employees (EmployeeID, Name, Department) VALUES
(1, 'John Doe', 'HR');
1. AND OPERATOR
• The AND operator is used to combine two or more conditions in
the WHERE clause. It ensures that all the conditions must be true
for a row to be included in the result set. In other words, it performs
a logical AND operation between the conditions.
• Syntax:
SELECT column1, column2
FROM table_name
WHERE condition1 AND condition2;
• Example:
SELECT *
FROM Employees
WHERE Department = 'HR' AND Salary > 50000;
2. OR OPERATOR
• The OR operator is used to combine two or more conditions in
the WHERE clause. It ensures that at least one of the conditions must
be true for a row to be included in the result set. In other words, it
performs a logical OR operation between the conditions.
• Syntax:
SELECT column1, column2
FROM table_name
WHERE condition1 OR condition2;
• Example:
SELECT *
FROM Employees
WHERE Department = 'HR' OR Salary > 50000;
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.
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example:
Select all products with a price between 10 and 20:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
• NOT BETWEEN
To display the products outside the range of the previous example,
use NOT BETWEEN.
Example
SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
• BETWEEN with IN
The following SQL statement selects all products with a price
between 10 and 20. In addition, the CategoryID must be either 1,2,
or 3:
Example
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20
AND CategoryID IN (1,2,3);
THE SQL ORDER BY
• The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;