MySQL Interview Questions and Answers
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
SELECT id, name, email, salary, IF(salary > 20000, 'Good', 'Average') AS type FROM `customers`;
A database index is the structure of a fact that improves the velocity of operations in a table. It can be created the usage of one or greater columns, presenting the foundation for each fast random lookups and efficient ordering of getting admission to records. Indexes are used to locate rows with specific column values quickly.
CREATE INDEX [index name] ON [table name]([column name]);
Employee
id | name | salary | |
---|---|---|---|
101 | Umesh Singh | [email protected] | 20000 |
102 | Sonu Singh | [email protected] | 10000 |
103 | Avinash | [email protected] | 7000 |
104 | Manish | [email protected] | 60000 |
105 | Rekha | [email protected] | 5000 |
106 | Shiv | [email protected] | 20000 |
For this, we can use the between operator with a where clause.
SELECT id, name, salary FROM Employee WHERE salary BETWEEN 5000 AND 25000;
NOW | CURRENT_DATE |
---|---|
NOW() give you the current date time in the format 'YYYY-MM_DD HH:MM: SS' | CURRENT_DATE() will only give you the current date in format "YYYY-MM_DD" |
Comparisons operators are used to comparing one expression to another value or expression. It is just like = , < , > , => , =<, <>
The standard way to perform case insensitive queries in SQL is to use the SQL upper or lower functions like the following:
select * from users where upper(first_name) = 'AJAY';
OR
select * from users where lower(first_name) = 'ajay';
The method is to make the field you are searching as uppercase or lowercase then also make the search string uppercase or lowercase as per the SQL function.
1. DDL
In MySQL, DDL is the short form for Data Definition Language, which is used in database schemas and descriptions while deciding how data should reside in the database.
Here’s a list of DDL Queries:
- CREATE
- ALTER
- DROP
- TRUNCATE
- COMMENT
- RENAME
2. DML
DML is a short form for Data Manipulation Language which is used in data manipulation and mostly includes common SQL statements to store, modify, retrieve, delete and update data in a database.
Here is the list of DML Queries:
- SELECT
- INSERT
- UPDATE
- DELETE
- MERGE
- CALL
- EXPLAIN PLAN
- LOCK TABLE
3. DCL
DCL is a short form for Data Control Language including commands which are concerned with User rights, permissions and other controls within the database system.
Here’s a list of queries for DCL:
- GRANT
- REVOKE
MySQL -u username -p database_name < file.sql
Here username is your database username like "root," database_name is your database name, file.sql is your SQL file name with complete path.
It is used to concatenate two or more strings.
SELECT CONCAT('BestInterview', ' ', 'Question') AS 'Name';
Table: Employee
id | name | |
---|---|---|
101 | Umesh Singh | [email protected] |
102 | Sonu Singh | [email protected] |
103 | Avinash | [email protected] |
104 | Manish | [email protected] |
105 | Rekha | [email protected] |
106 | Shiv | [email protected] |
107 | Manish | [email protected] |
108 | Sonu Singh | [email protected] |
The following SQL query can be used to obtain unique or different values for a column in MySQL Table. There are different values that can be assigned to one or more columns. You must separate the column names with a comma.
Syntax
SELECT DISTINCT(column_name) FROM your_table_name;
Example
SELECT DISTINCT(email) FROM Employee;
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”.