Faculty of Engineering and Technology
Parul Institute of Technology
Department of Computer Science & Engineering
Course: B.Tech – CSE
Subject: Database Management System
Unit 2
SQL
• DDL : Data Definition Language
• DQL : Data Query Language
• DML : Data Manipulation Language
• DCL : Data Control Language
• WHERE and LIKE
• Aggregate Functions
• Logical Operators: AND, OR
• BETWEEN, IN, NOT IN
• UNION, INTERSECT, MINUS
• Date Functions
• Character Functions
• Arithmetic Functions
:Overview:
DDL : Data Definition Language
• DDL is a set of SQL commands used to create, modify and
delete database structures but not data.
• List of DDL Commands:
1. CREATE : It is used to create a new table in database.
2. ALTER : It is used to change the structure or definition of a
created table. We can add, remove or change the
particular column name using ALTER. We can change table
name also.
CREATE Command
• Syntax:
CREATE TABLE table_name
(column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for column N);
• Example:
CREATE TABLE student
(Enrollment Number int,
Name varchar,
Contact Number varchar,
City varchar);
Output: This will create a table having
four columns.
ALTER Command for adding column
• Syntax:
ALTER TABLE table_name
ADD
column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for columnN ;
• Example:
ALTER TABLE Student
ADD
Email ID varchar;
Output: This will add a new column
named ‘Email ID’ into created table
‘Student’. Now this table contains five
columns.
ALTER Command for deleting column
• Syntax:
ALTER TABLE table_name
DROP
column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for columnN ;
• Example:
ALTER TABLE Student
DROP
Email ID varchar;
Output: This will remove a new column
named ‘Email ID’ from created table
‘Student’. Now this table contains four
columns.
ALTER Command for renaming column
• Syntax:
ALTER TABLE table_name
RENAME COLUMN existing name TO new
name;
• Example:
ALTER TABLE Student
RENAME COLUMN Enrollment Number TO
EnNo;
Output: This will rename a new column
named ‘Enrollment Number’. New name
of this particular name will be ‘EnNO’.
ALTER Command for renaming table
• Syntax:
ALTER TABLE table_name
RENAME new name of existing table;
• Example:
ALTER TABLE Student
RENAME Student1;
Output: This will rename existing table as
‘Student1’.
DQL : Data Query Language
• DQL is a SQL command used to fetch required data from the
database.
• SELECT is a DQL command.
SELECT Command for fetching all columns
• Syntax:
SELECT * FROM table_name;
• Example:
SELECT * FROM Student;
Output: This will show entire Student
table.
SELECT Command for fetching selected columns
• Syntax:
SELECT
column_name 1,
column_name 2,
…
column_name n
FROM table_name;
• Example:
SELECT Name, City FROM Student;
Output: This will show only two columns
of Student table.
DML : Data Manipulation Language
• DML is a set of SQL commands used to manipulate data.
• List of DML Commands:
1. INSERT : It is used to insert values into a created table in
database.
2. UPDATE : It is used to change the values in a created table.
3. DELETE : It is used to remove the records or values from
the table.
INSERT Command
• Syntax:
INSERT INTO table_name VALUES
(value 1, value 2, … value N);
• Example:
INSERT INTO Student VALUES
(1, ‘Aakash’,’Shah’,
20,’aakashshah@gmail.com’),
(2, ‘Sagar’,’Patel’,
21,’sagarpatel@gmail.com’);
Output: This will insert two rows into the
created Student table.
UPDATE Command
• Syntax:
UPDATE table_name
SET
column1_name=value1,
column2_name=value2,
…
columnn_name=valuen
WHERE condition;
• Example:
UPDATE Student
SET
City=‘Vadodara’
WHERE Enrollment Number=1;
Output: This will update city’s name
‘Vadodara’ for the particular record
having Enrollment Number 1.
DELETE Command
• Syntax:
DELETE FROM table_name
WHERE condition;
• Example:
DELETE FROM Student
WHERE Enrollment Number=1;
Output: This will delete the particular row
having record having Enrollment Number
1.
DCL : Data Control Language
• DCL is a set of SQL commands used to control the access
data stored in a database.
• List of DML Commands:
1. GRANT :
2. REVOKE:
How to create a User?
• Syntax:
CREATE USER user_name
WITH PASSWORD ‘password_value’ | VALID UNTIL ‘expiration’;
• Examples:
CREATE USER abc
WITH PASSWORD ‘abc1234’ | VALID UNTIL ‘Jan 1, 2020’;
CREATE USER def
WITH PASSWORD ‘def1234’ | VALID UNTIL ‘infinity’;
How to delete a User?
• Syntax:
DROP USER user_name;
• Example:
DROP USER abc;
• Syntax:
ALTER USER user_name TO new_name;
• Examples:
ALTER USER abc TO abc1;
How to rename a User?
GRANT
• Syntax:
GRANT privileges ON table_name TO user;
• Examples:
GRANT SELECT, INSERT, UPDATE, DELETE ON Student TO abc;
User “abc” can perform select, insert, update and delete on the table “Student”.
GRANT ALL ON Student TO def;
User “def” can perform all operations on the table “Student”.
GRANT SELECT ON Student TO PUBLIC;
Any user can perform only select operations on the table “Student”.
REVOKE
• Syntax:
REVOKE privileges ON table_name FROM user;
• Examples:
REVOKE ALL ON Student FROM abc;
Permissions are taken back from user “abc”.
WHERE
• The WHERE predicate is used for filter the records.
• It is used to extract only those records that fulfil a specified
condition.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition;
• Examples:
1. SELECT First_Name FROM student WHERE age<20;
2. SELECT First_Name, Last_Name FROM student WHERE
age<20;
3. SELECT First_Name, Last_Name FROM student WHERE
city=‘Baroda’;
WHERE
• The LIKE operator is used in a WHERE predicate to search for a specified pattern
in a column.
• There are two wildcards often used with LIKE: % and _
1. A% means string starts with A. Example: AB or ABC or ABCDE.
2. %A means any string that ends with A. Example: BA or CBA.
3. A%B means string starts with A but ends with B. Example: ACGB or ADB.
4. AB_C means string starts with AB then there is any one character and at last there is C.
5. A_C means string starts with A then there is any one character and at last there is C.
6. A_ means string starts with A then there is any one character at the end.
LIKE
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
LIKE pattern;
LIKE
• Examples:
1. SELECT First_Name FROM student WHERE age<20 LIKE ‘P%’;
2. SELECT First_Name FROM student WHERE age>25 LIKE ‘M%’;
3. SELECT First_Name FROM student WHERE age>25 LIKE ‘P%K’;
4. SELECT First_Name FROM student WHERE age>25 LIKE ‘%K’;
5. SELECT First_Name FROM student WHERE age>25 LIKE ‘_A%’;
LIKE
• The aggregate function simply refers to the calculations performed on
a data set to get a single number.
• Some common aggregate functions include:
1. COUNT
2. SUM
3. AVG
4. MIN
5. MAX
Aggregate Functions
Consider the following table. We will perform functions on this table.
COUNT Function
• Syntax:
SELECT COUNT (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT COUNT (first_name) FROM customers WHERE age<25;
Output: 2
2. SELECT COUNT (first_name) FROM customers WHERE first_name LIKE ‘J%’;
Output: 2
3. SELECT COUNT (customer_id) FROM customers;
Output: 5
4. SELECT COUNT (customer_id) FROM customers WHERE country= ‘USA’;
Output: 2
SUM Function
• Syntax:
SELECT SUM (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT SUM (age) FROM customers WHERE age<25;
Output: 44
2. SELECT SUM (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 56
3. SELECT SUM (customer_id) FROM customers;
Output: 15
4. SELECT SUM (age) FROM customers WHERE country= ‘USA’;
Output: 53
AVG Function
• Syntax:
SELECT AVG (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT AVG (age) FROM customers WHERE age<25;
Output: 25.6
2. SELECT AVG (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 28
3. SELECT AVG (customer_id) FROM customers;
Output: 3
4. SELECT AVG (age) FROM customers WHERE country= ‘USA’;
Output: 26.5
5. SELECT AVG (age*10) FROM customers WHERE country= ‘USA’;
Output: 265
MIN Function
• Syntax:
SELECT MIN (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT MIN (age) FROM customers;
Output: 22
2. SELECT MIN (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 25
3. SELECT MIN (customer_id) FROM customers;
Output: 1
4. SELECT MIN (age) FROM customers WHERE country= ‘USA’;
Output: 22
MAX Function
• Syntax:
SELECT MAX (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT MAX (age) FROM customers;
Output: 28
2. SELECT MAX (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 31
3. SELECT MAX (customer_id) FROM customers;
Output: 5
4. SELECT MAX (age) FROM customers WHERE country= ‘USA’;
Output: 31
• Logical operators are used along with the different
conditions. AND and OR are logical operators.
Logical Operators
Consider the following table. We will perform functions on this table.
• Examples:
1. SELECT * FROM customers WHERE age=22 AND
first_name=‘David’;
2. SELECT * FROM customers WHERE age=22 OR
first_name=‘David’;
3. SELECT * FROM customers WHERE country=‘UK’ AND
(age=22 OR first_name=‘David’);
Logical Operators
BETWEEN
• The SQL BETWEEN condition allows you to easily test if an expression is within a range of inclusive values.
• The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE
statement.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
BETWEEN value1 AND value2;
• It will return the records where the expression is within the range of value1 and value2.
BETWEEN
• Example 1:
SELECT * FROM customers
WHERE age
BETWEEN 25 AND 30;
• Example 2:
SELECT * FROM customers
WHERE age
NOT BETWEEN 25 AND 30;
IN and NOT IN
• IN operator allows you to easily test if the expression matches any value in the list of values.
• It is used to remove the need for multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE.
• You can also use NOT IN to exclude the rows in your list.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
IN (value1, value2, …, value n);
IN and NOT IN
• Example 1:
SELECT * FROM customers
WHERE age IN (22,28);
• Example 2:
SELECT * FROM customers
WHERE age NOT IN (22,28);
UNION
Consider the following tables. We will perform union operation on these tables.
UNION
SELECT Name FROM Teachers
UNION
SELECT Name FROM Students;
Output
UNION
SELECT * FROM Teachers
UNION
SELECT * FROM Students;
Output
INTERSECTION
Consider the following tables. We will perform intersection operation on these tables.
INTERSECTION
SELECT customer_id FROM Customers
INTERSECT
SELECT customer_id FROM Orders; Output
MINUS
Consider the following tables. We will perform minus operation on these tables.
MINUS
SELECT customer_id FROM Customers
MINUS
SELECT customer_id FROM Orders; Output
1. SELECT Current_date;
This command will show date in form of YYYY-MM-DD.
2. SELECT Current_time;
This command will show current time.
3. SELECT Current_timestamp;
This command will show current time and date.
Date Functions
1. Select lower('ABC’);
2. Select upper('abc’);
3. Select lower(upper('abc'));
4. Select upper(lower('ABC’));
5. Select length(‘Hello Good Morning’);
Character Functions
Output
Arithmetic Functions
Consider the following table for arithmetic operations.
Select customer_id, first_name, age+10 AS "age+10" from Customers;
Addition
Select customer_id, first_name, age-10 AS "age-10" from Customers;
Subtraction
Select customer_id, first_name, age*10 AS "age*10" from Customers;
Multiplication
Select customer_id, first_name, age/10 AS "age/10" from Customers;
Division
Select customer_id, first_name, age%10 AS "age%10" from Customers;
Modulus
4. Round function:
Select ROUND (213.456, 2);
Output => 213.46
Select ROUND (213.456, 1);
Output => 213.5
Some other functions
1. PI function:
Select PI ();
Output => 3.141592653589793
2. SQRT function:
Select SQRT (100);
Output => 10
3. SQUARE function:
Select SQUARE (5);
Output => 25
5. CEIL function:
Select ceil(23.34);
Output => 24
6. FLOOR function:
Select floor(23.34);
Output => 23
7. POWER function:
Select power(2,3);
Output => 8

rdbms parul university oracle dbms bca mca

  • 1.
    Faculty of Engineeringand Technology Parul Institute of Technology Department of Computer Science & Engineering Course: B.Tech – CSE Subject: Database Management System
  • 2.
  • 3.
    • DDL :Data Definition Language • DQL : Data Query Language • DML : Data Manipulation Language • DCL : Data Control Language • WHERE and LIKE • Aggregate Functions • Logical Operators: AND, OR • BETWEEN, IN, NOT IN • UNION, INTERSECT, MINUS • Date Functions • Character Functions • Arithmetic Functions :Overview:
  • 4.
    DDL : DataDefinition Language • DDL is a set of SQL commands used to create, modify and delete database structures but not data. • List of DDL Commands: 1. CREATE : It is used to create a new table in database. 2. ALTER : It is used to change the structure or definition of a created table. We can add, remove or change the particular column name using ALTER. We can change table name also.
  • 5.
    CREATE Command • Syntax: CREATETABLE table_name (column1_name data type for column1, column2_name data type for column2, … columnN_name data type for column N); • Example: CREATE TABLE student (Enrollment Number int, Name varchar, Contact Number varchar, City varchar); Output: This will create a table having four columns.
  • 6.
    ALTER Command foradding column • Syntax: ALTER TABLE table_name ADD column1_name data type for column1, column2_name data type for column2, … columnN_name data type for columnN ; • Example: ALTER TABLE Student ADD Email ID varchar; Output: This will add a new column named ‘Email ID’ into created table ‘Student’. Now this table contains five columns.
  • 7.
    ALTER Command fordeleting column • Syntax: ALTER TABLE table_name DROP column1_name data type for column1, column2_name data type for column2, … columnN_name data type for columnN ; • Example: ALTER TABLE Student DROP Email ID varchar; Output: This will remove a new column named ‘Email ID’ from created table ‘Student’. Now this table contains four columns.
  • 8.
    ALTER Command forrenaming column • Syntax: ALTER TABLE table_name RENAME COLUMN existing name TO new name; • Example: ALTER TABLE Student RENAME COLUMN Enrollment Number TO EnNo; Output: This will rename a new column named ‘Enrollment Number’. New name of this particular name will be ‘EnNO’.
  • 9.
    ALTER Command forrenaming table • Syntax: ALTER TABLE table_name RENAME new name of existing table; • Example: ALTER TABLE Student RENAME Student1; Output: This will rename existing table as ‘Student1’.
  • 10.
    DQL : DataQuery Language • DQL is a SQL command used to fetch required data from the database. • SELECT is a DQL command.
  • 11.
    SELECT Command forfetching all columns • Syntax: SELECT * FROM table_name; • Example: SELECT * FROM Student; Output: This will show entire Student table.
  • 12.
    SELECT Command forfetching selected columns • Syntax: SELECT column_name 1, column_name 2, … column_name n FROM table_name; • Example: SELECT Name, City FROM Student; Output: This will show only two columns of Student table.
  • 13.
    DML : DataManipulation Language • DML is a set of SQL commands used to manipulate data. • List of DML Commands: 1. INSERT : It is used to insert values into a created table in database. 2. UPDATE : It is used to change the values in a created table. 3. DELETE : It is used to remove the records or values from the table.
  • 14.
    INSERT Command • Syntax: INSERTINTO table_name VALUES (value 1, value 2, … value N); • Example: INSERT INTO Student VALUES (1, ‘Aakash’,’Shah’, 20,’aakashshah@gmail.com’), (2, ‘Sagar’,’Patel’, 21,’sagarpatel@gmail.com’); Output: This will insert two rows into the created Student table.
  • 15.
    UPDATE Command • Syntax: UPDATEtable_name SET column1_name=value1, column2_name=value2, … columnn_name=valuen WHERE condition; • Example: UPDATE Student SET City=‘Vadodara’ WHERE Enrollment Number=1; Output: This will update city’s name ‘Vadodara’ for the particular record having Enrollment Number 1.
  • 16.
    DELETE Command • Syntax: DELETEFROM table_name WHERE condition; • Example: DELETE FROM Student WHERE Enrollment Number=1; Output: This will delete the particular row having record having Enrollment Number 1.
  • 17.
    DCL : DataControl Language • DCL is a set of SQL commands used to control the access data stored in a database. • List of DML Commands: 1. GRANT : 2. REVOKE:
  • 18.
    How to createa User? • Syntax: CREATE USER user_name WITH PASSWORD ‘password_value’ | VALID UNTIL ‘expiration’; • Examples: CREATE USER abc WITH PASSWORD ‘abc1234’ | VALID UNTIL ‘Jan 1, 2020’; CREATE USER def WITH PASSWORD ‘def1234’ | VALID UNTIL ‘infinity’;
  • 19.
    How to deletea User? • Syntax: DROP USER user_name; • Example: DROP USER abc;
  • 20.
    • Syntax: ALTER USERuser_name TO new_name; • Examples: ALTER USER abc TO abc1; How to rename a User?
  • 21.
    GRANT • Syntax: GRANT privilegesON table_name TO user; • Examples: GRANT SELECT, INSERT, UPDATE, DELETE ON Student TO abc; User “abc” can perform select, insert, update and delete on the table “Student”. GRANT ALL ON Student TO def; User “def” can perform all operations on the table “Student”. GRANT SELECT ON Student TO PUBLIC; Any user can perform only select operations on the table “Student”.
  • 22.
    REVOKE • Syntax: REVOKE privilegesON table_name FROM user; • Examples: REVOKE ALL ON Student FROM abc; Permissions are taken back from user “abc”.
  • 23.
    WHERE • The WHEREpredicate is used for filter the records. • It is used to extract only those records that fulfil a specified condition. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition;
  • 24.
    • Examples: 1. SELECTFirst_Name FROM student WHERE age<20; 2. SELECT First_Name, Last_Name FROM student WHERE age<20; 3. SELECT First_Name, Last_Name FROM student WHERE city=‘Baroda’; WHERE
  • 25.
    • The LIKEoperator is used in a WHERE predicate to search for a specified pattern in a column. • There are two wildcards often used with LIKE: % and _ 1. A% means string starts with A. Example: AB or ABC or ABCDE. 2. %A means any string that ends with A. Example: BA or CBA. 3. A%B means string starts with A but ends with B. Example: ACGB or ADB. 4. AB_C means string starts with AB then there is any one character and at last there is C. 5. A_C means string starts with A then there is any one character and at last there is C. 6. A_ means string starts with A then there is any one character at the end. LIKE
  • 26.
    • Syntax: SELECT column1_name, column2_name,… columnN_name FROM table_name WHERE condition LIKE pattern; LIKE
  • 27.
    • Examples: 1. SELECTFirst_Name FROM student WHERE age<20 LIKE ‘P%’; 2. SELECT First_Name FROM student WHERE age>25 LIKE ‘M%’; 3. SELECT First_Name FROM student WHERE age>25 LIKE ‘P%K’; 4. SELECT First_Name FROM student WHERE age>25 LIKE ‘%K’; 5. SELECT First_Name FROM student WHERE age>25 LIKE ‘_A%’; LIKE
  • 28.
    • The aggregatefunction simply refers to the calculations performed on a data set to get a single number. • Some common aggregate functions include: 1. COUNT 2. SUM 3. AVG 4. MIN 5. MAX Aggregate Functions Consider the following table. We will perform functions on this table.
  • 29.
    COUNT Function • Syntax: SELECTCOUNT (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT COUNT (first_name) FROM customers WHERE age<25; Output: 2 2. SELECT COUNT (first_name) FROM customers WHERE first_name LIKE ‘J%’; Output: 2 3. SELECT COUNT (customer_id) FROM customers; Output: 5 4. SELECT COUNT (customer_id) FROM customers WHERE country= ‘USA’; Output: 2
  • 30.
    SUM Function • Syntax: SELECTSUM (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT SUM (age) FROM customers WHERE age<25; Output: 44 2. SELECT SUM (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 56 3. SELECT SUM (customer_id) FROM customers; Output: 15 4. SELECT SUM (age) FROM customers WHERE country= ‘USA’; Output: 53
  • 31.
    AVG Function • Syntax: SELECTAVG (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT AVG (age) FROM customers WHERE age<25; Output: 25.6 2. SELECT AVG (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 28 3. SELECT AVG (customer_id) FROM customers; Output: 3 4. SELECT AVG (age) FROM customers WHERE country= ‘USA’; Output: 26.5 5. SELECT AVG (age*10) FROM customers WHERE country= ‘USA’; Output: 265
  • 32.
    MIN Function • Syntax: SELECTMIN (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT MIN (age) FROM customers; Output: 22 2. SELECT MIN (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 25 3. SELECT MIN (customer_id) FROM customers; Output: 1 4. SELECT MIN (age) FROM customers WHERE country= ‘USA’; Output: 22
  • 33.
    MAX Function • Syntax: SELECTMAX (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT MAX (age) FROM customers; Output: 28 2. SELECT MAX (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 31 3. SELECT MAX (customer_id) FROM customers; Output: 5 4. SELECT MAX (age) FROM customers WHERE country= ‘USA’; Output: 31
  • 34.
    • Logical operatorsare used along with the different conditions. AND and OR are logical operators. Logical Operators Consider the following table. We will perform functions on this table.
  • 35.
    • Examples: 1. SELECT* FROM customers WHERE age=22 AND first_name=‘David’; 2. SELECT * FROM customers WHERE age=22 OR first_name=‘David’; 3. SELECT * FROM customers WHERE country=‘UK’ AND (age=22 OR first_name=‘David’); Logical Operators
  • 36.
    BETWEEN • The SQLBETWEEN condition allows you to easily test if an expression is within a range of inclusive values. • The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition BETWEEN value1 AND value2; • It will return the records where the expression is within the range of value1 and value2.
  • 37.
    BETWEEN • Example 1: SELECT* FROM customers WHERE age BETWEEN 25 AND 30; • Example 2: SELECT * FROM customers WHERE age NOT BETWEEN 25 AND 30;
  • 38.
    IN and NOTIN • IN operator allows you to easily test if the expression matches any value in the list of values. • It is used to remove the need for multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE. • You can also use NOT IN to exclude the rows in your list. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition IN (value1, value2, …, value n);
  • 39.
    IN and NOTIN • Example 1: SELECT * FROM customers WHERE age IN (22,28); • Example 2: SELECT * FROM customers WHERE age NOT IN (22,28);
  • 40.
    UNION Consider the followingtables. We will perform union operation on these tables.
  • 41.
    UNION SELECT Name FROMTeachers UNION SELECT Name FROM Students; Output
  • 42.
    UNION SELECT * FROMTeachers UNION SELECT * FROM Students; Output
  • 43.
    INTERSECTION Consider the followingtables. We will perform intersection operation on these tables.
  • 44.
    INTERSECTION SELECT customer_id FROMCustomers INTERSECT SELECT customer_id FROM Orders; Output
  • 45.
    MINUS Consider the followingtables. We will perform minus operation on these tables.
  • 46.
    MINUS SELECT customer_id FROMCustomers MINUS SELECT customer_id FROM Orders; Output
  • 47.
    1. SELECT Current_date; Thiscommand will show date in form of YYYY-MM-DD. 2. SELECT Current_time; This command will show current time. 3. SELECT Current_timestamp; This command will show current time and date. Date Functions
  • 48.
    1. Select lower('ABC’); 2.Select upper('abc’); 3. Select lower(upper('abc')); 4. Select upper(lower('ABC’)); 5. Select length(‘Hello Good Morning’); Character Functions Output
  • 49.
    Arithmetic Functions Consider thefollowing table for arithmetic operations.
  • 50.
    Select customer_id, first_name,age+10 AS "age+10" from Customers; Addition
  • 51.
    Select customer_id, first_name,age-10 AS "age-10" from Customers; Subtraction
  • 52.
    Select customer_id, first_name,age*10 AS "age*10" from Customers; Multiplication
  • 53.
    Select customer_id, first_name,age/10 AS "age/10" from Customers; Division
  • 54.
    Select customer_id, first_name,age%10 AS "age%10" from Customers; Modulus
  • 55.
    4. Round function: SelectROUND (213.456, 2); Output => 213.46 Select ROUND (213.456, 1); Output => 213.5 Some other functions 1. PI function: Select PI (); Output => 3.141592653589793 2. SQRT function: Select SQRT (100); Output => 10 3. SQUARE function: Select SQUARE (5); Output => 25 5. CEIL function: Select ceil(23.34); Output => 24 6. FLOOR function: Select floor(23.34); Output => 23 7. POWER function: Select power(2,3); Output => 8