0% found this document useful (0 votes)
11 views7 pages

Mysql Questions

Uploaded by

Min Khant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Mysql Questions

Uploaded by

Min Khant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

‭CODE WITH CHILL‬

‭MYSQL‬
‭(QUESTION FOR MYSQL EXAM)‬

‭01.‬‭Write True or False for the following statement. (10 marks)‬


‭a.‬ ‭The‬‭INSERT‬‭statement in SQL is used to delete records‬‭from a table.‬
‭b.‬ ‭The‬‭AVG()‬‭function in SQL is used to calculate the‬‭total (sum) of a numeric‬
‭column.‬
‭c.‬ ‭The‬‭WHERE‬‭clause in SQL is used to filter the results‬‭of a query based on a‬
‭specified condition.‬
‭d.‬ ‭DDL stands for Data Display Language.‬
‭e.‬ ‭The‬‭SUM()‬‭function in SQL is used to find the average‬‭value of a numeric‬
‭column.‬
‭f.‬ ‭The‬‭UPDATE‬‭statement in SQL is used to add new records‬‭to a table.‬
‭g.‬ ‭The‬‭GROUP BY‬‭clause in SQL is used to order records‬‭in ascending or‬
‭descending order.‬
‭h.‬ ‭The‬‭ALTER TABLE‬‭statement is used to change the data‬‭in a table.‬
‭i.‬ ‭The primary purpose of the‬‭JOIN‬‭clause in SQL is to‬‭filter records based on‬
‭a condition.‬
‭j.‬ ‭The‬‭DISTINCT‬‭keyword is used in SQL to retrieve unique‬‭values 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‬‭ INSERT‬‭statement?‬
‭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‬‭ DELETE‬‭statement 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 BY‬‭clause?‬
‭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‬‭ JOIN‬‭clause?‬
‭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‬
i‭v.‬ ‭ 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‬‭ WHERE‬‭clause 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‬‭ DELETE‬‭statement in SQL is used to ____ records from a table.‬
‭g.‬ ‭The‬‭ GROUP BY‬‭clause 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‬‭ JOIN‬‭clause in SQL is to combine rows from‬
‭two or more tables based on a related ____.‬
‭j.‬ ‭The‬‭ DISTINCT‬‭keyword 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 | [email protected] |‬
| 2 | Soyam
‭ | Mithal | [email protected] |‬
| 3 | Rohan
‭ | Soy | [email protected] |‬
| 4 | Rita
‭ | Smith | [email protected] |‬
| 5 | John
‭ | Smith | [email protected] |‬
| 6 | Sayam
‭ | Mitra | [email protected] |‬
| 7 | Shyam
‭ | Mishra | [email protected] |‬
| 8 | Soyam
‭ | Mithal | [email protected] |‬
| 9 | Rohan
‭ | Soy | [email protected] |‬
| 10 | Mita
‭ | Dahl | [email protected] |‬
+----+------------+-----------+-------------------------+‬

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 | [email protected]
‭ | 123456789 |‬

| 2 | John Smith
‭ | [email protected] | 123456789 |‬
| 3 | Gal Rao
‭ | [email protected] | 123456789 |‬
| 4 | Jakey Smith | [email protected]
‭ | 123456789 |‬
| 5 | Rama Saho
‭ |‬‭
[email protected]‬ | 123456789 |‬

| 6 | Maria Gaga
‭ | [email protected]‬ | 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‬

You might also like