Top 250 SQL Interview Questions and Answers
Updated 13 Feb 2025
Q201. what is SQL and what are SQL joins?
SQL is a programming language used to manage and manipulate relational databases. SQL joins are used to combine data from multiple tables.
SQL stands for Structured Query Language
It is used to manage and manipulate relational databases
SQL joins are used to combine data from multiple tables based on a common column
There are different types of SQL joins such as INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN
Example: SELECT * FROM table1 INNER JOIN table2 ON table1.column ...read more
Q202. How to find the Second highest salary from employees table. Write the logic for pre-order, inorder and post-order traversal of a binary tree
To find the second highest salary from employees table and traverse a binary tree in pre-order, in-order, and post-order.
To find the second highest salary, you can use a subquery or window function like ROW_NUMBER() or DENSE_RANK().
For pre-order traversal, visit the root node first, then recursively do a pre-order traversal of the left subtree, followed by the right subtree.
For in-order traversal, recursively do an in-order traversal of the left subtree, visit the root node, ...read more
Q203. How can we join a table without any identity columns?
You can join tables without identity columns using other unique columns or composite keys.
Use other unique columns or composite keys to join the tables
Consider using a combination of columns to create a unique identifier for joining
If no unique columns are available, consider using a combination of non-unique columns with additional logic to ensure accurate joins
Q204. Write a program to generate a hash function using my sql
Generate a hash function using MySQL
Use the MySQL built-in function SHA2() to generate a hash value
Specify the input string and the desired hash length as parameters
Example: SELECT SHA2('hello', 256) AS hash_value;
Q205. Tell me about normal forms in sql
Normal forms in SQL are rules used to design relational databases to minimize redundancy and improve data integrity.
First Normal Form (1NF) - Eliminate repeating groups and ensure each column contains atomic values.
Second Normal Form (2NF) - Meet 1NF requirements and all non-key attributes are fully functional dependent on the primary key.
Third Normal Form (3NF) - Meet 2NF requirements and eliminate transitive dependencies between non-key attributes.
Boyce-Codd Normal Form (BC...read more
Q206. What is the difference between SQL and No-SQL databse?
SQL databases are relational databases with structured data and predefined schema, while No-SQL databases are non-relational databases with flexible schema and unstructured data.
SQL databases use structured query language for defining and manipulating data, while No-SQL databases use various query languages like JSON or XML.
SQL databases have predefined schema, which means the structure of the data must be defined before inserting data, while No-SQL databases have dynamic sch...read more
Q207. Describe Join Concepts (SQL).
Join concepts in SQL are used to combine rows from two or more tables based on a related column between them.
Joins are used to retrieve data from multiple tables in a single query.
Types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
INNER JOIN returns rows when there is at least one match in both tables.
LEFT JOIN returns all rows from the left table and the matched rows from the right table.
RIGHT JOIN returns all rows from the right table and the matched ro...read more
Q208. What is Pyspark SQL?
Pyspark SQL is a module in Apache Spark that provides a SQL interface for working with structured data.
Pyspark SQL allows users to run SQL queries on Spark dataframes.
It provides a more concise and user-friendly way to interact with data compared to traditional Spark RDDs.
Users can leverage the power of SQL for data manipulation and analysis within the Spark ecosystem.
SQL Jobs
Q209. If clone table contain any privilege?
Clone tables inherit the privileges of the original table.
Clone tables do inherit the privileges of the original table they were cloned from.
Any user with privileges on the original table will also have the same privileges on the clone table.
This can be useful for maintaining consistent access control across tables.
Q210. What is identity in Sql.
Identity in SQL is a property used to uniquely identify each row in a table.
Identity columns are typically used as primary keys in tables
They automatically generate unique values for each new row
Identity values are often used for referencing and joining tables
Q211. What is SQL RANKING
SQL RANKING is a function used to assign a rank to each row within a result set based on a specific criteria.
RANK() function is used to assign a unique rank to each row within a partition of a result set.
DENSE_RANK() function is used to assign a unique rank to each row within a partition of a result set, without any gaps in the ranking.
ROW_NUMBER() function is used to assign a unique sequential integer to each row within a partition of a result set.
Q212. What are the isolation levels in sql server?
Isolation levels in SQL Server determine how transactions interact with each other.
There are five isolation levels: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SNAPSHOT, and SERIALIZABLE.
Each level has its own trade-offs between concurrency and consistency.
The default isolation level is READ COMMITTED.
Isolation levels can be set at the transaction level or for the entire database.
For example, the SNAPSHOT isolation level allows for consistent reads even when data is be...read more
Q213. How to Update a table?
To update a table, use SQL UPDATE statement with specified column values and conditions.
Use SQL UPDATE statement to specify the table name and set the new values for columns
Add a WHERE clause to specify the conditions for which rows to update
Example: UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
Q214. Find the product_id that got returned more than 10 times in a month and more than 3 times in a year?
Identify product_id with more than 10 returns in a month and 3 returns in a year.
Filter the dataset by returns in a month and returns in a year
Group the data by product_id and count the number of returns
Identify product_id with counts exceeding the thresholds
Q215. Write an sql query to change rows into columns and vice versa
Use SQL pivot function to change rows into columns and vice versa
Use the PIVOT function in SQL to transform rows into columns
Use the UNPIVOT function in SQL to transform columns into rows
Example: SELECT * FROM table_name PIVOT (SUM(value) FOR column_name IN (value1, value2, value3))
Example: SELECT * FROM table_name UNPIVOT (value FOR column_name IN (value1, value2, value3))
Q216. How to select column for buffers
Column selection for buffers depends on pH, ionic strength, and buffer capacity.
Consider the pH range of the buffer
Choose a buffer with appropriate pKa value
Consider the ionic strength of the buffer solution
Choose a buffer with high buffer capacity
Use online buffer selection tools for guidance
Q217. Update table 1 city from table 2 city value
To update table 1 city from table 2 city value, use SQL UPDATE statement with JOIN clause.
Use UPDATE statement with JOIN clause to join both tables on a common column
Specify the column to be updated in table 1 and the corresponding column in table 2
Use WHERE clause to filter the rows to be updated
Example: UPDATE table1 JOIN table2 ON table1.id = table2.id SET table1.city = table2.city WHERE table1.id = 1
Q218. Manipulate data in a column using SQL query
Use SQL query to manipulate data in a column
Use UPDATE statement to modify data in a column
Use SET keyword to specify the new value for the column
Use WHERE clause to filter the rows that need to be updated
Q219. explain DCL in sql ?
DCL stands for Data Control Language in SQL, used to control access to data stored in a database.
DCL commands include GRANT and REVOKE, which are used to give or revoke permissions on database objects.
GRANT command is used to give specific privileges to a user or role.
REVOKE command is used to take back privileges that were granted with the GRANT command.
Q220. What is SQL and help to feed dynamic data
SQL is a programming language used for managing and manipulating relational databases to feed dynamic data.
SQL stands for Structured Query Language
It is used to communicate with databases to perform tasks such as querying, updating, and deleting data
SQL can be used to retrieve dynamic data by using variables and parameters in queries
Example: SELECT * FROM table_name WHERE column_name = 'value'
Q221. What is Rownum ? Is expression Rownum >4 correct ?
Rownum is a pseudocolumn in Oracle that assigns a unique number to each row returned by a query.
Rownum starts with 1 and increments by 1 for each row returned by the query.
The expression Rownum > 4 is correct and will return all rows with a Rownum greater than 4.
Rownum can be used to limit the number of rows returned by a query, for example, 'SELECT * FROM table WHERE Rownum <= 10'.
Q222. What are dml statements in SQL?
DML statements in SQL are used to manipulate data in a database, including inserting, updating, deleting, and querying data.
DML stands for Data Manipulation Language.
Common DML statements include INSERT, UPDATE, DELETE, and SELECT.
INSERT is used to add new rows of data into a table.
UPDATE is used to modify existing data in a table.
DELETE is used to remove rows of data from a table.
SELECT is used to retrieve data from a table.
Q223. What is required field in sql how we write
Required field in SQL is a column that must contain a value before a record can be saved.
A required field is specified using the NOT NULL constraint in SQL.
Example: CREATE TABLE Students (ID INT NOT NULL, Name VARCHAR(50) NOT NULL);
Q224. Delete a single row
To delete a single row, use the DELETE statement with the WHERE clause.
Use the DELETE statement followed by the table name
Add the WHERE clause with the condition to identify the row to be deleted
Execute the query to delete the row
Q225. What is Table Lock in SQL
Table Lock in SQL is a mechanism that prevents other users from accessing a table while it is being used by a transaction.
Table Lock is used to control access to a table in a database.
It can be used to prevent other users from reading or writing to a table while a transaction is in progress.
There are different types of table locks such as shared lock, exclusive lock, and update lock.
Table locks can impact the performance of a database if not used properly.
Q226. How to join two different data sets
Joining two different data sets involves using a common key to merge the data into a single dataset.
Identify a common key in both data sets (e.g. customer ID, product ID)
Use a join operation (e.g. inner join, left join, right join) based on the common key
Choose the appropriate join type based on the desired outcome (e.g. include all data from one set, only matching data, etc.)
Q227. What are the standard transaction commands and what are they
Standard transaction commands are used in databases to manipulate data.
INSERT: Used to add new records to a table
SELECT: Used to retrieve data from a table
UPDATE: Used to modify existing records in a table
DELETE: Used to remove records from a table
Q228. 1) Do you know about SQL 2) Do you know about Oracle weblogic server
Yes, I have knowledge of SQL and Oracle WebLogic server.
I have experience writing complex SQL queries to retrieve and manipulate data.
I am familiar with Oracle WebLogic server and have worked on configuring and troubleshooting it.
I have knowledge of SQL functions, joins, and stored procedures.
I have experience in performance tuning SQL queries for optimal efficiency.
I have worked on deploying applications on Oracle WebLogic server and monitoring their performance.
Q229. Compare two tables and fetch records
Comparing two tables and fetching records based on specified criteria.
Identify common column(s) between the two tables
Use JOIN operation to combine the tables based on the common column(s)
Apply WHERE clause to filter records based on specified criteria
Q230. Explain your solution of sql
My solution involves writing SQL queries to extract, manipulate, and analyze data from databases.
Use SELECT statement to retrieve data from tables
Utilize WHERE clause to filter data based on specific conditions
Aggregate functions like SUM, AVG, COUNT can be used for calculations
JOIN tables to combine data from multiple sources
Use GROUP BY to group data based on certain columns
ORDER BY to sort data in ascending or descending order
Q231. What is difference between mongodb and SQL
MongoDB is a NoSQL database while SQL is a relational database management system.
MongoDB is schema-less, allowing for flexible data models.
SQL databases use structured query language for defining and manipulating data.
MongoDB is horizontally scalable, while SQL databases are vertically scalable.
SQL databases are better suited for complex queries and joins.
MongoDB is commonly used for big data and real-time applications.
SQL databases are ACID compliant, ensuring data integrity...read more
Q232. tell me about SQL? and tell me the commands using in sql?
SQL is a programming language used to manage and manipulate relational databases.
SQL stands for Structured Query Language.
It is used to create, modify, and query databases.
Some common SQL commands include SELECT, INSERT, UPDATE, and DELETE.
SQL can also be used to create tables, indexes, and views.
Examples of SQL commands: SELECT * FROM customers; INSERT INTO orders (customer_id, order_date) VALUES (1, '2021-01-01'); UPDATE products SET price = 10.99 WHERE id = 5; DELETE FROM ...read more
Q233. What is Index Fragmentation in SQL
Index fragmentation in SQL occurs when the logical order of pages in an index does not match the physical order in the data file.
Index fragmentation can lead to decreased query performance as the database engine has to scan more pages to retrieve data.
Fragmentation can be caused by frequent insertions, deletions, or updates on the indexed columns.
Rebuilding or reorganizing indexes can help reduce fragmentation and improve performance.
For example, running the 'ALTER INDEX REOR...read more
Q234. Explain about SQL and it types of queries
SQL is a programming language used to manage and manipulate relational databases. It has different types of queries.
SQL stands for Structured Query Language
It is used to manage and manipulate relational databases
Types of queries include SELECT, INSERT, UPDATE, DELETE, JOIN, etc.
SELECT is used to retrieve data from a database
INSERT is used to add new data to a database
UPDATE is used to modify existing data in a database
DELETE is used to remove data from a database
JOIN is used ...read more
Q235. what is merge statement and use case ?
Merge statement is used to perform insert, update, or delete operations in a single statement based on a condition.
Combines INSERT, UPDATE, and DELETE operations into a single statement
Used to synchronize two tables based on a condition
Improves performance by reducing the number of SQL statements needed
Can be used to insert new records, update existing records, or delete records in a single operation
Q236. what is count() and count(*)
count() and count(*) are SQL functions used to count the number of rows in a table.
count() counts the number of non-null values in a specific column
count(*) counts the total number of rows in a table
Example: SELECT count(column_name) FROM table_name;
Example: SELECT count(*) FROM table_name;
Q237. what is join key
Join key is a field used to match records from two different data sets in a database or data processing system.
Join key is used in JOIN operations to combine data from multiple tables based on a common field.
It is typically used in SQL queries to specify the columns that should be used to match records between tables.
For example, in a customer and order database, the customer ID could be the join key to link customer information with their orders.
Q238. What is join command ?
Join command is used to combine rows from two or more tables based on a related column between them.
Join command is used in SQL to combine data from multiple tables.
It is used to retrieve data from two or more tables based on a related column between them.
There are different types of joins like inner join, left join, right join, and full outer join.
Example: SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;
Q239. What is difference between drop, delete, truncate
Drop, delete, and truncate are SQL commands used to remove data from a table, but they differ in their functionality and implications.
DROP command is used to remove a table or database from the database schema. It deletes the table definition and all its data.
DELETE command is used to remove specific rows from a table based on a condition. It does not delete the table structure.
TRUNCATE command is used to remove all rows from a table, but it does not delete the table structur...read more
Q240. Do you know how to set up tables
Yes, I am familiar with setting up tables.
I know how to properly place tablecloths and napkins.
I am able to arrange silverware and glassware in the correct order.
I can set up centerpieces and other decorations as needed.
Q241. How do nested queries/subqueries work
Nested queries/subqueries are queries within another query, allowing for more complex and specific data retrieval.
Nested queries are enclosed within parentheses and can be used in SELECT, FROM, WHERE, and HAVING clauses.
They can be used to filter results based on the output of another query, or to retrieve data from related tables.
Nested queries can also be used to perform calculations or aggregate functions on the results of the outer query.
Example: SELECT * FROM table1 WHER...read more
Q242. How do you apply SQL for ur project
SQL is used for data retrieval, manipulation and management in the project.
SQL queries are used to retrieve data from databases
SQL is used to manipulate data in databases
SQL is used to manage databases
Examples include retrieving user information from a database, updating user information, and creating new tables in a database
Q243. Expalin about refresh mechanism in sql
Refresh mechanism in SQL is used to update the data in a materialized view or a snapshot to reflect changes in the base tables.
Refresh mechanism can be manual or automatic.
Manual refresh requires the user to explicitly refresh the materialized view using a command like REFRESH MATERIALIZED VIEW.
Automatic refresh can be set up using options like ON COMMIT or ON DEMAND.
Examples of automatic refresh include fast refresh and complete refresh.
Fast refresh updates only the changed ...read more
Q244. What are SQL DML queries
SQL DML queries are used to manipulate data in a database.
DML stands for Data Manipulation Language
Used to insert, update, delete data in a database
Examples: INSERT INTO, UPDATE, DELETE FROM
Q245. What is SQL & Name The TCL Commands?
SQL is a programming language used to manage and manipulate relational databases. TCL commands include COMMIT, ROLLBACK, and SAVEPOINT.
SQL stands for Structured Query Language and is used to manage and manipulate relational databases.
TCL (Transaction Control Language) commands are used to manage transactions in SQL.
Examples of TCL commands include COMMIT, ROLLBACK, and SAVEPOINT.
Q246. How to update a query in SQL
To update a query in SQL, use the UPDATE statement with the SET clause and WHERE clause.
Use the UPDATE statement followed by the name of the table to be updated
Use the SET clause to specify the new values for the columns
Use the WHERE clause to specify which rows to update
Example: UPDATE employees SET salary = 50000 WHERE department = 'IT'
Q247. Do you know about procedure in SQL
Yes, procedures in SQL are used to group a set of SQL statements into a single unit of work.
Procedures can be used to improve code reusability and maintainability.
They can accept input parameters and return output parameters.
Procedures can be called from other SQL statements or applications.
Example: CREATE PROCEDURE GetEmployeeDetails AS SELECT * FROM Employees;
Example: EXEC GetEmployeeDetails;
Q248. How do you seperate name from emails for example *****,***** etc.. We need to get name form those mails in sql
Use SQL string functions like SUBSTRING and CHARINDEX to separate name from emails.
Use CHARINDEX to find the position of the '@' symbol in the email address.
Use SUBSTRING to extract the characters before the '@' symbol as the name.
Consider handling cases where there are multiple names or special characters in the email address.
Q249. What is stored procedure in SQL
Stored procedure in SQL is a precompiled collection of SQL statements that can be executed by calling the procedure name.
Stored procedures help improve performance by reducing network traffic and improving security.
They can be used to encapsulate complex SQL logic for reuse.
Parameters can be passed to stored procedures for dynamic execution.
Stored procedures can also be used for error handling and transaction management.
Q250. What is Date function in SQl
The Date function in SQL is used to retrieve the current system date.
The Date function returns the current date in the format 'YYYY-MM-DD'.
It does not include the time component.
It is commonly used in SQL queries to filter or group data based on the current date.
Top Interview Questions for Related Skills
Interview Questions of SQL Related Designations
Interview experiences of popular companies
Reviews
Interviews
Salaries
Users/Month