CODE WITH CHILL
MYSQL
(QUESTION FOR MYSQL EXAM)
01.Write True or False for the following statement. (10 marks)
a. TheINSERTstatement in SQL is used to delete recordsfrom a table.
b. TheAVG()function in SQL is used to calculate thetotal (sum) of a numeric
column.
c. TheWHEREclause in SQL is used to filter the resultsof a query based on a
specified condition.
d. DDL stands for Data Display Language.
e. TheSUM()function in SQL is used to find the averagevalue of a numeric
column.
f. TheUPDATEstatement in SQL is used to add new recordsto a table.
g. TheGROUP BYclause in SQL is used to order recordsin ascending or
descending order.
h. TheALTER TABLEstatement is used to change the datain a table.
i. The primary purpose of theJOINclause in SQL is tofilter records based on
a condition.
j. TheDISTINCTkeyword is used in SQL to retrieve uniquevalues from a
column.
02.Choose the correct answer. ( 10 marks)
a. Which SQL statement is used to retrieve all columns from a table named
"employees"?
i. SELECT * FROM employees;
ii. SHOW COLUMNS FROM employees;
iii. DISPLAY ALL FROM employees;
iv. GET COLUMNS employees;
b. What is the purpose of the SQL INSERTstatement?
i. To retrieve data from a table.
ii. To delete records from a table.
iii. To add new records to a table.
iv. To update existing records in a table.
c. Which SQL clause is used to filter the results of a query based on a
specified condition?
i. ORDER BY
ii. WHERE
iii. GROUP BY
iv. HAVING
d. What does the SQL acronym "DDL" stand for?
i. Data Definition Language
ii. Data Description Language
iii. Data Display Language
iv. Database Design Language
e. Which SQL function is used to find the total (sum) of a numeric column?
i. COUNT()
ii. SUM()
iii. AVG()
iv. MAX()
f. What does the SQL DELETEstatement do?
i. Updates existing records.
ii. Adds new records.
iii. Deletes records from a table.
iv. Retrieves records.
g. In MySQL, what is the purpose of the GROUP BYclause?
i. To filter records based on a condition.
ii. To order records in ascending or descending order.
iii. To group records based on the values in one or more columns.
iv. To join multiple tables.
h. Which SQL statement is used to change the structure of an existing table?
i. ALTER TABLE
ii. MODIFY TABLE
iii. CHANGE TABLE
iv. UPDATE TABLE
i. What is the purpose of the SQL JOINclause?
i. To filter results based on a condition.
ii. To change the structure of a table.
iii. To combine rows from two or more tables based on a related
column.
iv. To calculate aggregate functions.
j. Which SQL statement is used to retrieve unique values from a column?
i. UNIQUE
ii. DISTINCT
iii. UNIQUES
iv. DIFFERENT
03.Fill in the blank. ( 10 marks)
a. The SQL statement to retrieve all columns from a table named
"employees" is SELECT ____ FROM employees;.
b. The SQL INSERT statement is used to add ____ records to a table.
c. The WHEREclause in SQL is used to filter the results of a query based on a
specified ____.
d. DDL stands for Data ____ Language.
e. The SQL function used to find the total (sum) of a numeric column is
____()
.
f. The DELETEstatement in SQL is used to ____ records from a table.
g. The GROUP BYclause in SQL is used to group records based on the
values in one or more ____.
h. The SQL statement to change the structure of an existing table is ALTER
____
.
i. The primary purpose of the JOINclause in SQL is to combine rows from
two or more tables based on a related ____.
j. The DISTINCTkeyword is used in SQL to retrieve ____ values from a
column.
04.Use your computer and solve the following problems.
a. W
rite a mysql statement to find the concatenated first_name, last_name where
age of the employee is greater than 30. (5 marks)
Suppose the employee table is -
------------------------+------------------------------+----------+----------+
+
| first_name
| last_name | age | dept |
+------------------------+------------------------------+----------+----------+
| Mesa
| Loop | 30 | Acct |
| Smith
| Oak | 27 | Devl |
| John
| Jorz | 37 | QA |
| Hary
| Gaga | 32 | QA |
+
+------------------------+------------------------------+----------+----------
b. W
rite a mysql statement to get item id, item, price of the most expensive item.(4
marks)
Suppose the item table is-
-----------+--------------+----------------+
+
| ITEM_ID
| ITEM | PRICE |
+-----------+--------------+----------------+
| 1001
| Book | 1200 |
| 1002
| Pen | 930 |
| 1003
| Bag | 1430 |
| 1004
| Copy | 1030 |
+-----------+--------------+----------------+
c. Write a mysql statement to select data of only CS OR IT departments.(4 marks)
Suppose the table is -
----+--------------+------------+-----+
+
| id | name
| department | age |
+----+--------------+------------+-----+
| 1 | Maria Gloria | CS
| 22 |
| 2 | John Smith
| IT | 23 |
| 3 | Gal Rao
| CS | 22 |
| 4 | Jakey Smith | EC
| 24 |
| 5 | Rama Saho
| IT | 22 |
| 6 | Maria Gaga
| EC | 23 |
+----+--------------+------------+-----+
d. W
rite a MySQL statement to select data of all departments in descending order
by age. (5 marks)
Suppose the table is -
----+--------------+------------+-----+
+
| id | name
| department | age |
+----+--------------+------------+-----+
| 1 | Maria Gloria | CS
| 22 |
| 2 | John Smith
| IT | 23 |
| 3 | Gal Rao
| CS | 22 |
| 4 | Jakey Smith | EC
| 24 |
| 5 | Rama Saho
| IT | 22 |
| 6 | Maria Gaga
| EC | 23 |
+----+--------------+------------+-----+
e. Write a mysql statement to determine the age of each of the students.(5 marks)
Suppose the table is-
----+--------------+------------+------------+
+
| id | name
| department | birth |
+----+--------------+------------+------------+
| 1 | Maria Gloria | CS
| 1994-03-12 |
| 2 | John Smith
| IT | 1993-02-07 |
| 3 | Gal Rao
| CS | 1992-09-11 |
| 4 | Jakey Smith | EC
| 1990-08-31 |
| 5 | Rama Saho
| IT | 1994-12-09 |
| 6 | Maria Gaga
| EC | 1993-10-09 |
+----+--------------+------------+------------+
f. Write a mysql statement to retrieve names beginning with 'm' or ‘M’ (4 marks)
(Table is same as question 04.e)
g. W
rite a mysql statement to find the name, birth, department name, department
block from the given tables. ( 6 marks)
----+--------------+------------+------------+
+
| id | name
| dept_id | birth |
+----+--------------+------------+------------+
| 1 | Maria Gloria | 2
| 1994-03-12 |
| 2 | John Smith
| 1 | 1993-02-07 |
| 3 | Gal Rao
| 4 | 1992-09-11 |
| 4 | Jakey Smith | 2
| 1990-08-31 |
| 5 | Rama Saho
| 1 | 1994-12-09 |
| 6 | Maria Gaga
| 4 | 1993-10-09 |
+----+--------------+------------+------------+
+---------+--------------------------+------------+
| dept_id | dept_name
| dept_block |
+---------+--------------------------+------------+
|
1 | Computer Science | B-Block |
|
2 | Information Technology | C-Block |
|
3 | Mechanical | A-Block |
|
4 | Electronic Communication | D-Block |
+---------+--------------------------+------------+
h. Delete the duplicate row from the table. ( 5 marks)
(use only one sql syntax)
----+------------+-----------+-------------------------+
+
| id | first_name | last_name | email
|
+----+------------+-----------+-------------------------+
| 1 | John
| Smith | john@[Link] |
| 2 | Soyam
| Mithal | [Link]@[Link] |
| 3 | Rohan
| Soy | [Link]@[Link] |
| 4 | Rita
| Smith | rita@[Link] |
| 5 | John
| Smith | john@[Link] |
| 6 | Sayam
| Mitra | [Link]@[Link] |
| 7 | Shyam
| Mishra | shyam@[Link] |
| 8 | Soyam
| Mithal | [Link]@[Link] |
| 9 | Rohan
| Soy | [Link]@[Link] |
| 10 | Mita
| Dahl | mita@[Link] |
+----+------------+-----------+-------------------------+
i. P rint 2 random students from the table. (Table is same as 04.h) ( 4 marks)
j. Update the table in id 4,6 . ( 4 marks)
name = your name, email = your email , phone = your phone;
(use only one sql syntax)
+----+--------------+------------+---------------------+
id | name
| | email | phone
|
+----+--------------+------------+---------------------+
| 1 | Maria Gloria | maria@[Link]
| 123456789 |
| 2 | John Smith
| john@[Link] | 123456789 |
| 3 | Gal Rao
| gal@[Link] | 123456789 |
| 4 | Jakey Smith | jakey@[Link]
| 123456789 |
| 5 | Rama Saho
|
rama@[Link] | 123456789 |
| 6 | Maria Gaga
| mara@[Link] | 123456789 |
+----+--------------+------------+---------------------+
k. Display details of highest and lowest data using one syntax. ( 4 marks)
----+----------+--------+
+
| id | emp_name | salary |
+----+----------+--------+
| 1 | Smith
| 30000 |
| 2 | Joney
| 20000 |
| 3 | Mariya
| 40000 |
| 4 | Zoya
| 35000 |
| 5 | Smith
| 25000 |
| 6 | Rosy
| 75000 |
+----+----------+--------+
he output show be like this :
T
+----+----------+--------+
| id | emp_name | salary |
+----+----------+--------+
| 2 | Joney
| 20000 |
| 6 | Rosy
| 75000 |
+----+----------+--------+
l. Display the first 4 highly paid salaries using mysql. ( 4 marks)
----+----------+--------+
+
| id | emp_name | salary |
+----+----------+--------+
| 1 | Smith
| 30000 |
| 2 | Joney
| 20000 |
| 3 | Mariya
| 40000 |
| 4 | Zoya
| 35000 |
| 5 | Smith
| 25000 |
| 6 | Rosy
| 75000 |
+----+----------+--------+
m. Add the phone column in the table. ( 4 marks)
----+----------+--------+
+
| id | emp_name | salary |
+----+----------+--------+
| 1 | Smith
| 30000 |
| 2 | Joney
| 20000 |
| 3 | Mariya
| 40000 |
| 4 | Zoya
| 35000 |
| 5 | Smith
| 25000 |
| 6 | Rosy
| 75000 |
+----+----------+--------+
n. P
hone columns are null. Add phone number 123456789 in all queries. ( 4
marks)
(Use only one syntax)
----+----------+--------+-------+
+
| id | emp_name | salary | phone |
+----+----------+--------+-------+
| 1 | Smith
| 30000 | NULL |
| 2 | Joney
| 20000 | NULL |
| 3 | Mariya
| 40000 | NULL |
| 4 | Zoya
| 35000 | NULL |
| 5 | Smith
| 25000 | NULL |
| 6 | Rosy
| 75000 | NULL |
+----+----------+--------+-------+
o. Replace 123456789 as “Nothing” in the above table. ( 4 marks)
p. C
oncat the “------>” between id and emp_name in the above table. ( 4
marks)
END QUESTION