You are on page 1of 47

S.I.E.

S College of Arts, Science and Commerce(Autonomous)


Sion(W), Mumbai – 400 022.

CERTIFICATE

This is to certify that Miss./Mr. _________CHIRAG DINAKAR SHETTY_______________


Roll No. FCS2324091 has successfully completed the necessary course of
experiments in the subject of Beginning MySQL during the
academic year 2023 – 2024 complying with the requirements of University of Mumbai,
for the course of FYBSc Computer Science [Semester-I].

Prof. In-Charge

Dr. Abuzar Ansari Examiner’s Signature & Date

Head of the Department College Seal


Dr. Manoj Singh
Index Page
Practical Description Page Date Faculty
No No Signature
1 BASICS
a) Create a database
b) Show a database 3 23/08/23
c) Delete a database
d) Set current database

2 TABLES USING MySQL


a) Create a table
b) Insert data in table
c) Use of ALTER command
d) Insert new value
e) SELECT command 6 30/08/23
f) Update using WHERE clause.
g) Drop columns
h) Delete records
i) Delete table

3 VIEWS
a) Create a view
b) Display the data in view
c) Update the data
d) Retrieve data using SELECT 12 06/09/23
e) Delete a view
f) Delete a record from a view

4 STRING FUNCTIONS 18 13/09/23

5 DATE FUNCTIONS 28 27/09/23

6 MATH FUNCTIONS 32 27/10/23

7 JOIN FUNCTIONS
a) Inner join
b) Left Outer Join 40 04/10/23
c) Right Outer Join
d) Cross Join
MYSQL Practical 1: Basics of MySQL

Aim: Write a Mysql program to


-create database emp1 and emp2
-Show databases that are created
-Delete emp2 database
-Set current database to emp1

Program must include Description and Syntax before main code Starts

Code:
/* THE FOLLOWING COMMANDS WERE INPUTED IN THE MYSQL WORKBENCH
*/

CREATE DATABASE EMP1;


USE EMP1;
CREATE TABLE EMP_DATA (
EMP1ID INT PRIMARY KEY,
EMPNAME VARCHAR(15),
EMPADD VARCHAR(15),
EMPCONTACT INT(10)
);
INSERT INTO EMP_DATA VALUES(1,'ROHAN SETH','MULUND',1234567890);
INSERT INTO EMP_DATA VALUES(2,'RONAK SETU','BHANDUP',1234567890);
INSERT INTO EMP_DATA VALUES(3,'RAGHAV SHETH','MALAD',1234567890);
INSERT INTO EMP_DATA VALUES(4,'ROMAN SAN','KURLA',1234567890);
INSERT INTO EMP_DATA VALUES(5,'ROHIT SHETTY','THANE',1234567890);
COMMIT;
CREATE DATABASE EMP2;
USE EMP2;
CREATE TABLE EMP_DATA (
EMP1ID INT PRIMARY KEY,
EMPNAME VARCHAR(15),
EMPADD VARCHAR(15),
EMPCONTACT INT(10)
);
INSERT INTO EMP_DATA VALUES(1,'ROHAN SETH','MULUND',1234567890);
INSERT INTO EMP_DATA VALUES(2,'RONAK SETU','BHANDUP',1234567890);
INSERT INTO EMP_DATA VALUES(3,'RAGHAV SHETH','MALAD',1234567890);
INSERT INTO EMP_DATA VALUES(4,'ROMAN SAN','KURLA',1234567890);
INSERT INTO EMP_DATA VALUES(5,'ROHIT SHETTY','THANE',1234567890);
COMMIT;

/* THE FOLLOWING COMMANDS WERE INPUTED IN THE TERMINAL */


USE EMP1;
SELECT * FROM EMP_DATA;
USE EMP2;
SELECT * FROM EMP_DATA;
DROP DATABASE EMP2;
USE EMP2;
/* TO CHECK WHETHER THE DATABASE EXISTS OR NOT*/
USE EMP1;
/*TO SET THE CURRENT DATABASE AS EMP1*/
SELECT * FROM EMP_DATA
/*TO DISPLAY THE CONTENTS OF EMP1*/
OUTPUT:
MySQL Practical 2: Tables using MySQL
Aim:
Write a MySQL program and do the following:-
A.to create following table and describe structure

B. Insert following data in table and display all data

C. Make use of ALTER and add new field gender with 1 limit of value.
D. Insert new value to gender.
E. Select and Display Id , name and salary column from above table.
F. Increment the salary of the customer named Ramesh by 10000 by using the WHERE
clause along with the UPDATE statement.
G. Drop the column Gender and display the values.
H. Delete the records of customers who are over 25 years of age.
I. Create another table orders with oid as integer not null, date as varchar not null, custid as
integer not null, amount as decimal with limit of 18 and 2.
J. Delete the table order.

Description:
1. SQL provides the CREATE TABLE statement to create a new table in a given
database. An SQL query to create a table must define the structure of a table. The
structure consists of the name of a table and names of columns in the table with each
column's data type. Note that each table must be uniquely named in a database.
2. SQL provides the INSERT INTO (table name) VALUES() statement to insert table
data in a given database. It must follow the order and restrictions specified in the
CREATE TABLE statement.
3. We use the COMMIT statement to save the data.
4. The ALTER statement is used to modify drop or add columns or data to the database.
5. To add values to the newly generated column GENDER, we used the
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 1;
Here the id is used to specify the location where the data needs to be added.
6. To select only particular column/columns, we use the statement SELECT x,y,z FROM
EMP_DATA(table name); where x,y,z are the columns we would like to see.
7. To delete the column ‘GENDER’ we used
ALTER TABLE EMP_DATA
DROP COLUMN GENDER;

8. To delete only the employees that where older than 25yrs from the table we used
DELETE FROM EMP_DATA WHERE AGE > 25;
The delete statement permanently deletes data from the table.

Syntax:
1. Following is the basic syntax of a SQL CREATE TABLE statement −
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
• CREATE TABLE is the keyword telling the database system what you want to do. In
this case, you want to create a new table. The unique name or identifier for the table
follows the CREATE TABLE statement.
• Then in brackets comes the list defining each column in the table and what sort of
data type it is. The syntax becomes clearer with the following example.
2. The syntax of INSERT INTO statement is –
INSERT INTO table_name VALUES();
• Remember that characters in VARCHAR need to be inserted within ‘’ and the
numbers can be inserted without ‘’ .
3. The syntax of COMMIT is COMMIT.
4. The syntax of ALTER statement is –
ALTER TABLE table_name
function name column name column datatype(in some cases);
5. The syntax for update statement is –
UPDATE table_name
SET column_name = "value"
WHERE ID = position;
6. The rest of the syntax is in the Description itself.
Code:
USE EMP1;
CREATE TABLE EMP_DATA (
ID INT PRIMARY KEY,
EMPNAME VARCHAR(15) NOT NULL,
AGE INT(11) NOT NULL,
ADDRESS VARCHAR(25),
SALARY DECIMAL(18,2)
);
INSERT INTO EMP_DATA VALUES(1,'RAMESH',32,'AHMEDABAD',2000.00);
INSERT INTO EMP_DATA VALUES(2,'KHILAN',25,'DELHI',1500.00);
INSERT INTO EMP_DATA VALUES(3,'KAUSHIK',23,'KOTA',2000.00);
INSERT INTO EMP_DATA VALUES(4,'CHAITALI',25,'MUMBAI',6500.00);
INSERT INTO EMP_DATA VALUES(5,'HARDIK',27,'BHOPAL',8500.00);
INSERT INTO EMP_DATA VALUES(6,'KOMAL',22,'HYDERABAD',4500.00);
INSERT INTO EMP_DATA VALUES(7,'MUFFY',24,'INDORE',10000.00);
COMMIT
ALTER TABLE EMP_DATA
ADD GENDER VARCHAR(1);
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 1;
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 2;
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 3;
UPDATE EMP_DATA
SET GENDER = "F"
WHERE ID = 4;
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 5;
UPDATE EMP_DATA
SET GENDER = "F"
WHERE ID = 6;
UPDATE EMP_DATA
SET GENDER = "M"
WHERE ID = 7;
COMMIT
SELECT ID , EMPNAME, SALARY FROM EMP_DATA;
UPDATE EMP_DATA
SET SALARY = SALARY + 10000
WHERE ID = 1;
ALTER TABLE EMP_DATA
DROP COLUMN GENDER;
DELETE FROM EMP_DATA WHERE AGE > 25;
COMMIT
CREATE TABLE ORDERS (
OID INT NOT NULL PRIMARY KEY,
DATE VARCHAR(15) NOT NULL,
CUSTID INT(11) NOT NULL,
AMOUNT DECIMAL(18,2)
);
SELECT * FROM ORDERS;
DROP TABLE ORDERS;
Output:
MySQL Practical 3: Views
Aim:
Write a MySQL program and do the following:-
A. To create following table and describe structure

B. Insert following data in table and display all data

C.CREATE a VIEW CUSTOMERS_VIEW which must have all values from table.
D. Display all the values of created view.
E. CREATE another VIEW BUYERS_VIEW which must have all values from customer
table where salary is greater than 3000.
F. Updates the age of Ramesh to 35 in the above created CUSTOMERS_VIEW .
G. Retrieve the record with ID value 6 using the SELECT statement
H. updates the NAME and AGE column values in the CUSTOMERS_VIEW of the record
with ID value 3.
I. modify/update the age values of all the records in the CUSTOMERS_VIEW with
increment of 3.
J. CREATE VIEW CUSTOMERS_VIEW1,CUSTOMERS_VIEW2 And
CUSTOMERS_VIEW3 selecting all values from customers table.
K. Delete view Customers view1
L. Delete a record from the third_view created on the CUSTOMERS table created above
where age is equal to 22.

Description:
1. SQL provides the CREATE TABLE statement to create a new table in a given
database. An SQL query to create a table must define the structure of a table. The
structure consists of the name of a table and names of columns in the table with each
column's data type. Note that each table must be uniquely named in a database.
2. SQL provides the INSERT INTO (table name) VALUES() statement to insert table
data in a given database. It must follow the order and restrictions specified in the
CREATE TABLE statement.

3. We use the COMMIT statement to save the data.

4. The ALTER statement is used to modify drop or add columns or data to the database.

5. To create a VIEW, we use the statement -


CREATE VIEW CUSTOMERS_VIEW(name of the view) AS
SELECT ID,NAME,AGE,ADDRESS,SALARY(what we wanted to insert into the
view)
FROM EMP_DATA(table name);
To display a VIEW, we use - SELECT * FROM CUSTOMERS_VIEW;

6. To select only particular column/columns, we use the statement SELECT


x,y,z FROM EMP_DATA(table name); where x,y,z are the columns we
would like to see.

7. To update something we use –


UPDATE (table/view name)
SET column_name = "value";

8. To delete the VIEW ‘CUSTOMERS_VIEW1’ we used


DROP VIEW CUSTOMERS_VIEW1;

9. To delete only the record that had age = 22 yrs from the table we used DELETE
FROM CUSTOMERS_VIEW3 WHERE AGE = 22;
The delete statement permanently deletes data from the table.
However this did not change the VIEW as we had previously incremented the age,
making all the ages greater than 22.

Syntax:
1. Following is the basic syntax of a SQL CREATE TABLE statement −
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
• CREATE TABLE is the keyword telling the database system what
you want to do. In this case, you want to create a new table. The
unique name or identifier for the table follows the CREATE
TABLE statement.
• Then in brackets comes the list defining each column in the table
and what sort of data type it is. The syntax becomes clearer with
the following example.
2. The syntax of INSERT INTO statement is –
INSERT INTO table_name VALUES();
• Remember that characters in VARCHAR need to be inserted within ‘’
and the numbers can be inserted without ‘’ .
3. The syntax of COMMIT is COMMIT.
4. The syntax of creating a VIEW is –

CREATE VIEW (name of the view) AS

SELECT (what columns we wanted to insert into the view)

FROM (table name);

5. The syntax of ALTER statement is –


ALTER TABLE table_name
function name column name column datatype (in some cases);
6. The syntax for update statement is –
UPDATE table_name
SET column_name = "value"
WHERE ID = position;
7. The rest of the syntax is in the Description itself.
Code:
CREATE DATABASE PRACTICAL3;
USE PRACTICAL3;
CREATE TABLE EMP_DATA (
ID INT PRIMARY KEY,
NAMESS VARCHAR(15) NOT NULL,
AGE INT(11) NOT NULL,
ADDRESS VARCHAR(25),
SALARY DECIMAL(18,2)
);
INSERT INTO EMP_DATA VALUES(1,'RAMESH',32,'AHMEDABAD',2000.00);
INSERT INTO EMP_DATA VALUES(2,'KHILAN',25,'DELHI',1500.00);
INSERT INTO EMP_DATA VALUES(3,'KAUSHIK',23,'KOTA',2000.00);
INSERT INTO EMP_DATA VALUES(4,'CHAITALI',25,'MUMBAI',6500.00);
INSERT INTO EMP_DATA VALUES(5,'HARDIK',27,'BHOPAL',8500.00);
INSERT INTO EMP_DATA VALUES(6,'KOMAL',22,'HYDERABAD',4500.00);
INSERT INTO EMP_DATA VALUES(7,'MUFFY',24,'INDORE',10000.00);
COMMIT
ALTER TABLE EMP_DATA
RENAME COLUMN NAMESS TO NAME;
CREATE VIEW CUSTOMERS_VIEW AS
SELECT ID,NAME,AGE,ADDRESS,SALARY
FROM EMP_DATA;
SELECT * FROM CUSTOMERS_VIEW;
CREATE VIEW BUYERS_VIEW AS
SELECT ID,NAME,AGE,ADDRESS,SALARY
FROM EMP_DATA
WHERE SALARY>3000;
UPDATE CUSTOMERS_VIEW
SET AGE = 35
WHERE NAME = 'RAMESH';
SELECT ID,NAME,AGE,ADDRESS,SALARY FROM EMP_DATA WHERE ID = 6;
UPDATE CUSTOMERS_VIEW
SET AGE = 35 , NAME = 'CHIRAG'
WHERE ID = 3;
UPDATE CUSTOMERS_VIEW
SET age = age + 3;
CREATE VIEW CUSTOMERS_VIEW1 AS
SELECT ID,NAME,AGE,ADDRESS,SALARY
FROM EMP_DATA;
CREATE VIEW CUSTOMERS_VIEW2 AS
SELECT ID,NAME,AGE,ADDRESS,SALARY
FROM EMP_DATA;
CREATE VIEW CUSTOMERS_VIEW3 AS
SELECT ID,NAME,AGE,ADDRESS,SALARY
FROM EMP_DATA;
DROP VIEW CUSTOMERS_VIEW1;
DELETE FROM CUSTOMERS_VIEW3 WHERE AGE = 22;RS;
Output:
MySQL Practical 4: String functions
Aim:

Q1. Perform following ASCII() function on string ‘SQL stands for Structured Query
Language.’
Description:
ASCII stands for American Standard Code for Information Interchange.
It assigns unique values for 128 alphabetic, numeric or special additional characters.
Here, the function returns the ASCII value of only the first character of the string. The
command used is –
SELECT STRINGS, ASCII(STRINGS) AS ASCII_Value
FROM STRINGCONTAINER
WHERE id = 1;
Syntax:
SELECT (column_name), ASCII(column_name) AS ASCII_Value
FROM (table_(name)
WHERE id = (id_number);
Code:
CREATE DATABASE PRACTICAL4;
USE PRACTICAL4;
CREATE TABLE STRINGCONTAINER (
ID INT PRIMARY KEY,
STRINGS VARCHAR(255)
);
INSERT INTO STRINGCONTAINER
VALUES ('SQL stands for Structured Query Language.');
SELECT STRINGS, ASCII(STRINGS) AS ASCII_Value
FROM STRINGCONTAINER
WHERE ID = 1;
Output:
Q2. Return the character for each integer.
Description:
The CHAR() function returns the ASCII code of the specified integer from 0 to 255. You can
also specify an expression that returns an integer value. The command used is –
SELECT CHAR(ASCII_Value) AS CHARACTERS
FROM STRINGCONTAINER
WHERE ID=1;
Syntax:
SELECT CHAR(column_name) AS CHARACTERS
FROM (table_name)
WHERE ID=(id_number);
Code:
CREATE DATABASE PRACTICAL4;
USE PRACTICAL4;
CREATE TABLE STRINGCONTAINER (
ID INT PRIMARY KEY,
STRINGS VARCHAR(255)
);
INSERT INTO STRINGCONTAINER
VALUES ('SQL stands for Structured Query Language.');
ALTER TABLE STRINGCONTAINER
ADD ASCII_VALUE INT;
UPDATE STRINGCONTAINER
SET ASCII_VALUE = ASCII(STRINGS)
WHERE ID = 1;
SELECT CHAR(ASCII_VALUE) AS CHARACTERS
FROM STRINGCONTAINER
WHERE ID=1;
SELECT CHAR(83) AS CHAR83
Output:

Q3. Return concatenate with separator for string ‘TCS and Company with separator’
Description:
Concatenate function is used to join two or more strings together. A separator is a type of
parameter which decides what should be between two or more strings.
Syntax:
CONCAT_WS(separator,input_string1,input_string2,[...input_stringN]);

Code:
SELECT CONCAT_WS(' AND ','TCS','COMPANY');
Output:
Q4. Return concatenated string SMART and POINT.
Description:
Concatenate function is used to join two or more strings together. A separator is a type of
parameter which decides what should be between two or more strings.
Syntax:
CONCAT(input_string1,input_string2,[...input_stringN]);

Code:
SELECT CONCAT('SMART','POINT');
Output:
Q5. Return the left 5 character from string SMARTPOINT.
Description:
The LEFT() function is used to SELECT a sub string from the left of given size or
characters.
Syntax:
SELECT LEFT(‘string’, location);
Code:
SELECT LEFT(‘SMARTPOINT’, 5);
Output:

Q.6 Return the length of the given string PHILLIPINES.

Description:
The LENGTH() function is used to find out the length of a string.
Syntax:
SELECT LENGTH ('string');
Code:
SELECT LENGTH (' PHILLIPINES');
Output:

Q.7 Return the lowercase of the given string VARIABLES.

Description:
The LCASE() function is used to find out the lowercase version of a string.
Syntax:
SELECT LCASE ('string');
Code:
SELECT LCASE ('VARIABLES');
Output:
Q.8 Return the uppercase of the given string ALPHANIA.

Description:
The UCASE() function is used to find out the lowercase version of a string.
Syntax:
SELECT UCASE ('string');
Code:
SELECT UCASE ('alphania');
Output:

Q9. Replace the word HELLO with HI from HELLOWORLD.

Description:
To replace the word "HELLO" with "HI" in the string "HELLO WORLD", you
can use the REPLACE() function.
In this query, the REPLACE() function takes three arguments:
• The original string ('HELLO WORLD').
• The string you want to replace ('HELLO').
• The string you want to replace it with ('HI').
This query replaces all occurrences of "HELLO" with "HI" in the input string, and the result
is "HI WORLD".
Syntax:
SELECT REPLACE(input_string,old_substring,newsubstring);
Code:
SELECT REPLACE('HELLO WORLD','HELLO','HI') AS REPLACED_STRING;
Output:

Q10. REVERSE the string Hello World


Description:
To reverse the string "Hello World", we use the REVERSE() function. This query reverses
the characters in the string "HELLO WORLD" resulting in "DLROW OLLEH"
which is the reversed string.
Syntax:
SELECT REVERSE(input_string);
Code:
SELECT REVERSE('HELLO WORLD') AS REVERSED_STRING;
Output:
11. Return the substring from index 2 to 5 of the character HELLO WORLD
Description:
To return the substring from index 2 to 5 of the string "HELLO WORLD"
you can use the SUBSTRING() function which allows you to
extract a portion of a string.
In this query:
• The first argument is the input string, which is 'HELLO WORLD'.
• The second argument (2) is the starting index (1-based index) of the substring you want.
• The fourth argument (5) is the length of the substring you want to extract.
Syntax:
SELECT SUBSTRING(input_string,start_position,length);
Code:
SELECT SUBSTRING('Hello World',2,5) AS SUBSTRING_RESULT;
Output:
MySQL Practical 5: Date function in MySQL
Aim: Date function using MySQL
1. Write a MySQL command to display current date with time.
Description:
The NOW() function returns the current date and time.
Code:
SELECT NOW() AS 'Current Date and Time';
Output:

2. Write a MySQL command to display current date.


Description:
The CURDATE() function returns the current date.
Code:
SELECT CURDATE() AS 'Current Date';
Output:

3. Write a MySQL command to use date format for 2025-05-21 with all options
available.
Description:
The DATE FORMAT() function returns the date in the specified format.
Formats specified to give the respective outcome are:
• W% -> gives the day of the week ( in words)
• M% -> gives the month of the specified date ( in words)
• Y% -> gives the year of the specified date (full year ex: 2023)
• %m -> gives the month in number
• %d -> gives the day in number
• %y -> gives the year (ex: 23)
• %j -> gives the days passed in the year
Code:
SELECT DATE_FORMAT('2025-05-21', '%W %M %Y') AS 'Formatted Date';
SELECT DATE_FORMAT('2025-05-21', '%m/%d/%Y') AS 'Formatted Date';
SELECT DATE_FORMAT('2025-05-21', '%d-%m-%y') AS 'Formatted Date';
SELECT DATE_FORMAT('2025-05-21', '%j') AS 'Formatted Date';
Output:

4. Write a MySQL command to add date with 10 day , 5 month and 6 year on 2022-06-
12.
Description:
Here we used DATE_ADD function which can be used to increase the day, month, or
year respectively.
Code:
SELECT DATE_ADD(DATE_ADD(DATE_ADD('2022-06-12', INTERVAL 10
DAY), INTERVAL 5 MONTH), INTERVAL 6 YEAR) AS 'Date after 6 yrs 5
months and 10 days';

Output:

5. Write a MySQL command to display name of day, day of month , day of week, day of
year for 2021-05-21.
Description:
Here we used the following functions:
• DAYNAME() – It returns the name of the given day.
• DAYOFMONTH() – It returns the day of the month.
• DAYOFWEEK() – It returns the weekday index of the argument.
• DAYOFYEAR() – It returns the day of the year.
Code:
SELECT DAYNAME('2021-05-21') AS 'Day Name',
DAYOFMONTH('2021-05-21') AS 'Day of Month',
DAYOFWEEK('2021-05-21') AS 'Day of Week',
DAYOFYEAR('2021-05-21') AS 'Day of Year';

Output:
6. Write a MySQL command to display sysdate and utc date
Description:
The SYSDATE() function returns the system date when the function gets executed
whereas the UTC_DATE() function returns the current UTC date
Code:
SELECT SYSDATE() AS 'System Date',
UTC_DATE() AS 'UTC Date';
Output:

7. Write a mysql command to display week , weekday and week of year


Description:
Here we used the following functions:
• WEEK() -> Returns the week number.
• WEEKDAY() -> Returns the week day index.
• WEEKOFYEAR() -> Returns the calendar week of the day.
Code:
SELECT WEEK('2021-05-21') AS 'Week',
WEEKDAY('2021-05-21') AS 'Weekday',
WEEKOFYEAR('2021-05-21') AS 'Week of Year';

Output:

8. Write a MySQL command to display last day of 2034-05-11.


Description:
The LAST_DAY() function returns the last day of the month for the argument.
Code:
SELECT LAST_DAY('2034-05-11') AS 'Last Day of 2034-05-11.';
Output:
MySQL Practical 6: Math function in MySQL
Aim: Math function using MySQL

List of Math Functions: ~


1. ABS() function:
Description:
It returns the absolute value
Code:
SELECT ABS(9) AS 'OUTPUT';
Output:

2. ACOS() function:
Description:
It returns the arc cosine
Code:
SELECT ACOS(0) AS 'OUTPUT';
Output:

3. ASIN() function:
Description:
It returns the arc sine
Code:
SELECT ASIN(0) AS 'OUTPUT';
Output:
4. ATAN() function:
Description:
It returns the arc tangent
Code:
SELECT ATAN(1) AS 'OUTPUT';
Output:

5. ATAN2(),ATAN() function:
Description:
It returns the arc tangent of the two arguments
Code:
SELECT ATAN2(0),ATAN(1) AS 'OUTPUT';
Output:

6. CEIL() function:
Description:
It returns the smallest integer value not less than the argument
Code:
SELECT CEIL(10.9) AS 'OUTPUT';
Output:

7. CEILING() function:
Description:
It returns the smallest integer value not less than the argument
Code:
SELECT CEILING(10.9) AS 'OUTPUT';
Output:
8. CONV() function:
Description:
It convert numbers between different number bases.
It’s syntax is CONV(number, from_base, to_base)
Code:
SELECT CONV(10,2,5) AS 'OUTPUT';
Output:

9. SIN() function:
Description:
It returns the sine
Code:
SELECT SIN(90) AS 'OUTPUT';
Output:

10. COS() function:


Description:
It returns the cosine
Code:
SELECT COS(90) AS 'OUTPUT';
Output:
11. TAN() function:
Description:
It returns the tangent
Code:
SELECT TAN(90) AS 'OUTPUT';
Output:

12. COT() function:


Description:
It returns the cotangent
Code:
SELECT COT(90) AS 'OUTPUT';
Output:

13. CRC32() function:


Description:
It computes a cyclic redundancy check value
Code:
SELECT CRC32('string') AS 'OUTPUT';
Output:
14. DEGREES() function:
Description:
It converts radians to degrees
Code:
SELECT DEGREES(1.05) AS 'OUTPUT';
Output:

15. EXP() function:


Description:
It raises to the power of
Code:
SELECT EXP(8) AS 'OUTPUT';
Output:

16. FLOOR() function:


Description:
It returns the largest integer value not greater than the argument
Code:
SELECT FLOOR(10.9) AS 'OUTPUT';
Output:
17. LN() function:
Description:
It returns the natural logarithm of the argument
Code:
SELECT LN(10) AS 'OUTPUT';
Output:

18. LOG() function:


Description:
It returns the natural logarithm of the first argument
Code:
SELECT LOG(10) AS 'OUTPUT';
Output:

19. LOG10() function:


Description:
It returns the base-10 logarithm of the argument
Code:
SELECT LOG10(10) AS 'OUTPUT';
Output:

20. LOG2() function:


Description:
It returns the base-2 logarithm of the argument
Code:
SELECT LOG2(10) AS 'OUTPUT';
Output:
21. MOD() function:
Description:
It returns the remainder.
It’s syntax is MOD(divident,divisor)
Code:
SELECT MOD(11,2) AS 'OUTPUT';
Output:

22. PI() function:


Description:
It returns the value of pi
Code:
SELECT PI() AS 'OUTPUT';
Output:

23. POW() function:


Description:
It returns the argument raised to the specified power
Code:
SELECT POW(2,3) AS 'OUTPUT';
Output:

24. POWER() function:


Description:
It returns the argument raised to the specified power
Code:
SELECT POWER(2,3) AS 'OUTPUT';
Output:
25. RADIANS() function:
Description:
It returns argument converted to radians
Code:
SELECT RADIANS(90) AS 'OUTPUT';
Output:
MySQL Practical 7: JOIN FUNCTIONS IN MYSQL
Aim: Write a mysql command to create following table.
Perform Inner join , Left and Right join , cross join on the given table.

To create the above table:


Code:
CREATE DATABASE PRACTICALASS;

USE PRACTICALASS;

CREATE TABLE EMPDATA (

Id INT PRIMARY KEY,

Name VARCHAR(255),

Department VARCHAR(20),

Salary INT,

Gender VARCHAR(10),

Age INT,

City VARCHAR(255)

);

INSERT INTO EMPDATA

VALUES (1001,"JOHN DOE","IT",35000,"MALE",25,"LONDON");

INSERT INTO EMPDATA

VALUES (1002,"MARY SMITH","HR",45000,"FEMALE",27,"LONDON");

INSERT INTO EMPDATA

VALUES (1003,"JAMES BROWN","FINANCE",50000,"MALE",28,"LONDON");

INSERT INTO EMPDATA


VALUES (1004,"MIKE WALKER","FINANCE",50000,"MALE",28,"LONDON");

INSERT INTO EMPDATA

VALUES (1005,"LINDA JONES","HR",75000,"FEMALE",26,"LONDON");

INSERT INTO EMPDATA

VALUES (1006,"ANURAG MOHANTY","IT",35000,"MALE",25,"MUMBAI");

INSERT INTO EMPDATA

VALUES (1007,"PRIYANKA DEVANGAN","HR",45000,"FEMALE",27,"MUMBAI");

INSERT INTO EMPDATA

VALUES (1008,"SAMBIT MOHANTY","IT",50000,"MALE",28,"MUMBAI");

INSERT INTO EMPDATA

VALUES (1009,"PRANAYA KUMAR","IT",50000,"MALE",28,"MUMBAI");

INSERT INTO EMPDATA

VALUES (1010,"HINA SHARMA","HR",75000,"FEMALE",26,"MUMBAI");

CREATE TABLE PROJECTS (

ProjectId INT PRIMARY KEY,

Title VARCHAR(255),

ClientId INT,

EmployeeId INT,

StartDate DATETIME,

EndDate DATETIME

);

INSERT INTO PROJECTS

VALUES (1,"Develop eCommerece Website from scratch",1,1003,'2021-04-27


19:02:42','2021-05-27 19:02:42');

INSERT INTO PROJECTS

VALUES (2,"WordPress website for our company",1,1002,'2021-04-27 19:02:42','2021-05-27


19:02:42');

INSERT INTO PROJECTS

VALUES (3,"Manage our company servers",2,1007,'2021-04-27 19:02:42','2021-05-27


19:02:42');

INSERT INTO PROJECTS


VALUES (4,"Hosting account is not working",3,1009,'2021-04-27 19:02:42','2021-05-27
19:02:42');

INSERT INTO PROJECTS

VALUES (5,"MySQL database from my desktop application",4,1010,'2021-04-27


19:02:42','2021-05-27 19:02:42');

INSERT INTO PROJECTS

VALUES (6,"Develop new WordPress plugin for my buisness",2,0,'2021-04-27


19:02:42','2021-05-27 19:02:42');

INSERT INTO PROJECTS

VALUES (7,"Migrate web application and database to new server",2,0,'2021-04-27


19:02:42','2021-05-27 19:02:42');

INSERT INTO PROJECTS

VALUES (8,"Android Application Development",4,1004,'2021-04-27 19:02:42','2021-05-27


19:02:42');

INSERT INTO PROJECTS

VALUES (9,"Hosting account is not working",3,1001,'2021-04-27 19:02:42','2021-05-27


19:02:42');

INSERT INTO PROJECTS

VALUES (10,"MySQL database from my desktop application",4,1008,'2021-04-27


19:02:42','2021-05-27 19:02:42');

INSERT INTO PROJECTS

VALUES (11,"Develop new WordPress plugin for my buisness",2,0,'2021-04-27


19:02:42','2021-05-27 19:02:42');
The tables needed to be created are:

1. Inner Join

DESCRIPTION:
SQL provides the INNER JOIN statement to join value into give Table

Syntax:
Following is the basic syntax of a SQL INNER JOIN statement −
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name

Code:
SELECT EmployeeId,Name,Department,City,Title,ClientId FROM EMPDATA
INNER JOIN PROJECTS ON EMPDATA.Id=PROJECTS.EmployeeId ORDER BY
EmployeeId;

Output:
2. Outer Join (left and right):

For left join


DESCRIPTION:
SQL provides the LEFT JOIN statement to join value into give Table.

Syntax:
Following is the basic syntax of a SQL LEFT JOIN statement −
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

Code:

SELECT Id,Name,Department,City,Title,EmployeeId FROM EMPDATA


LEFT JOIN PROJECTS ON EMPDATA.Id=PROJECTS.EmployeeId
ORDER BY Id;
Output:

For right join


DESCRIPTION:
SQL provides the RIGHT JOIN statement to join value into give Table.

Syntax
Following is the basic syntax of Right Join in SQL −
SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;

Code:

SELECT EmployeeId,Name,Department,City,Title,ClientId FROM


EMPDATA RIGHT JOIN PROJECTS ON
EMPDATA.Id=PROJECTS.EmployeeId;

Output:
3. For Full join:

DESCRIPTION:
We need to use the UNION of the RIGHT JOIN and LEFT JOIN statement to Full
join value into give Table.

Syntax:
SELECT * FROM table1 LEFT JOIN PROJECTS ON
table1.columnX=table2.columnY
UNION
SELECT * FROM table1 RIGHT JOIN PROJECTS ON
table1.columnX=table2.columnY;

Code:
SELECT * FROM EMPDATA LEFT JOIN PROJECTS ON
EMPDATA.Id=PROJECTS.EmployeeId
UNION
SELECT * FROM EMPDATA RIGHT JOIN PROJECTS ON
EMPDATA.Id=PROJECTS.EmployeeId;

Output:
4. For Cross join:
DESCRIPTION: SQL provides the CROSS JOIN statement to join value into give
Table

Syntax
Following is the basic syntax of the Cross Join query in SQL −
SELECT column_name(s)
FROM table1
CROSS JOIN table
Code:

SELECT * FROM EMPDATA CROSS JOIN PROJECTS ON


EMPDATA.Id=PROJECTS.EmployeeId;

Output:

You might also like