In this post, we have listed 9 frequently asked SQL queries interview questions with answers. This list can be useful for freshers as well as experienced candidates.
- What is SQL?
SQL or Structured Query Language is a language used in programming and designed for managing data held in a relational database management system.
- What are tables in SQL?
The table is a collection of record and its information at a single view.
- What is the SQL Query to find second highest salary of Employee?
There are various methods of finding second highest salary of Employee in SQL. You can either use SQL Join or Subquery to find the answer. Take a look at this SQL query using Subquery:
- How do you write an SQL Query to print the name of the distinct employee whose DOB is between 01/01/1960 to 31/12/1975?
Here you can use BETWEEN clause to get all records whose date fall between two dates.
- What is the SQL Query to find Max Salary from each department?
You can find the maximum salary for each department by grouping all records by DeptId and then using MAX() function to calculate the maximum salary in each group or each department.
- Write SQL Query to display the current date.
There is a built-in function in SQL called GetDate() which returns the current timestamp. This will work in Microsoft SQL Server, other vendors like Oracle and MySQL also has equivalent functions.
- What is the difference between CHAR and VARCHAR2 datatype in SQL?
Char is used for character strings of fixed length while varchar2 is used for character strings of variable length.
- What do you mean by data manipulation language?
DML or Data manipulation Language is used to access or manipulate data in the database.
It allows us to perform the following functions:
- Retrieve or fetch data
- Update data in database
- Insert data or rows in database
- Delete data from database
- What is data definition language?
Data definition language or DDL is used to execute queries like CREATE , ALTER and DELETE.