MySQL Interview Questions and Answers

Last updated on Feb 07, 2024
  • Share
MySQL Interview Questions

MYSQL is one of the most successful and leading pathways toward data administration careers. You will be amazed to know that this database service holds a total of 46.83% share in the relational database market. So to make your career and prepare for interviews in this field would be a good choice. Today we will help with these interviews by providing you with some MYSQL Interview Questions and Answers. MYSQL is one of the most popular database technologies used in the database industry. Popular companies like Microsoft, Amazon, Oracle, and IBM are using this technology on a vast basis to manage and store their data. According to one survey, nowadays more than 90% of organizations are using OSDBMS i.e. Open Source Database Management System. But to handle this database, professionals must know the MYSQL programming language.

Quick Facts About MySQL
What is the latest version of MySQL? 8.0.22 released in 19th October 2020
When was MySQL first released? 23 May 1995
Who developed MySQL? Oracle Corporation.
What language does MySQL use? C and C++ language
About License GNU Public License
Official Website https://www.mysql.com

MySQL Query Interview Questions

Here in this article, we will be listing frequently asked MySQL Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q51. What are aggregate functions in MySQL?
Answer

The MySQL aggregate function performs a calculation on a set of values, and it returns a single value as output. It ignores NULL values when it performs calculation except for the COUNT function.

MySQL provides many aggregate functions that are listed below.

  • AVG()
  • COUNT()
  • SUM()
  • MIN()
  • MAX() etc
Q52. What is difference between function and procedure in MySQL?
Answer
Function Procedure
The function returns the single value which is anyhow mandatory. The procedure returns zero or N values.
They only work with a statement: Select They can work with multiple statements: Insert, Update, Delete, Select.
In function, transactions are not possible In the procedure, transactions are possible
Error handling is not possible With try-catch, error handling is possible.
Q53. In Mysql, what is joins? Explain
Answer

In Mysql, joins are used to retrieve data from multiple tables. It is performed whenever two or more tables are joined.

There are three types of MySQL joins:-

  • MySQL INNER JOIN
    SELECT columns FROM table_1 INNER JOIN table_2 ON table_1.column = table_2.column;
  • MySQL LEFT JOIN
    SELECT columns FROM table_1 LEFT JOIN table_2 ON table_1.column = table_2.column;
  • MySQL RIGHT JOIN
    SELECT columns FROM table_1 RIGHT JOIN table_2 ON table_1.column = table_2.column;
Q54. What is the difference between CHAR and VARCHAR in MySQL?
Answer
  • CHAR can have a maximum of 255 characters, but VARCHAR can hold a maximum of 65,535 characters.
  • CHAR field is a fixed length, but VARCHAR is a variable length field.
  • CHAR uses static memory allocation, but VARCHAR uses dynamic memory allocation.
Q55. How we can get the current date in MySQL?
Answer

We can use SELECT NOW();

Q56. Write a query to find duplicate rows In table?
Answer

SELECT std_id, COUNT(std_id) as cnt FROM Student GROUP by std_id having cnt > 1

Q57. How to display odd rows in Employee table in Mysql?
Answer

SELECT id, name, department FROM Employee where MOD(id,2) = 1

Q58. What are the stored procedures in MySQL? Also, write an example.
Answer

The stored procedure is like a subprogram in a typical computing language which is stored in the database. A stored procedure contains the name, list of parameters, and the SQL statements. All the relational database system works as pillars for stored procedures.

In this example, we are creating a simple procedure called job_data, when this procedure will get executed, all the data from "jobs" tables will get displayed.

DELIMITER //
CREATE PROCEDURE GetAllPages()
BEGIN
    SELECT * FROM pages WHERE title LIKE '%MySQL Interview Questions%';
END //
DELIMITER ;

Q59. Write a query to display even rows in student table using MySQL?
Answer

SELECT * FROM Student where MOD(id,2) = 0

Q60. How to display top 10 rows in Mysql?
Answer

SELECT * FROM 'TableName' WHERE 'status' = 1 LIMIT 10

Conclusion

In MYSQL Database, data is stored in tabular form and that is why we also call it a Relational Database Management System. With the help of it, users can develop an infinite number of applications but it is mainly used for web applications. Talking about platforms, it can run on various platforms like LINUX, UNIX, and WINDOWS and is reliable, fast, and very easy to use. We hope these questions will help you to clear your core concepts regarding MYSQL. Let us help you with some short and important tips which might help you with your interviews-

  • MYSQL is a programming language, so always avoid YES and NO answers.
  • If you don’t know the answer, simply say I don't know rather than pretending you know.
  • Always carry a pen and notepad with you.
  • If you are stuck somewhere don’t panic, just stay calm and think out loud.
  • Go with the expectation that you will reject a lot, as “Failure is the key to Success”.
Reviewed and verified by Umesh Singh
Umesh Singh

My name is Umesh Singh having 11+ experience in Node.JS, React JS, Angular JS, Next JS, PHP, Laravel, WordPress, MySQL, Oracle, JavaScript, HTML and CSS etc. I have worked on around 30+ projects. I lo...