{"id":101820,"date":"2024-11-26T12:17:50","date_gmt":"2024-11-26T06:47:50","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/"},"modified":"2024-12-05T19:55:38","modified_gmt":"2024-12-05T14:25:38","slug":"sql-interview-questions","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/","title":{"rendered":"35+ SQL Interview Questions and Answers"},"content":{"rendered":"\n<p>Landing a job that requires SQL skills often means preparing for a challenging interview. SQL is a foundational technology for database management, so employers test candidates on various concepts ranging from basic to advanced-level queries. This blog covers common SQL interview questions and their answers to help you succeed in your next interview.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-sql\"><strong>What is SQL?<\/strong><\/h2>\n\n\n\n<p>SQL or Structured Query Language, is a programming language designed for managing and querying relational databases. It allows you to create, read, update, and delete data in databases, making it essential for working with data-driven systems. It forms the backbone of most modern applications, making it a must-have skill for developers, analysts, and data professionals alike.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-title-link\">SQL Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master SQL and Database management with this SQL course: Practical training with guided projects, AI support, and expert instructors.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>7 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-button\">\n                Take SQL Course Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-sql-questions\"><strong>Basic SQL Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-what-are-the-types-of-sql-commands\"><strong>1. What are the types of SQL commands?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">SQL commands<\/a> are grouped into the following categories:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DDL (Data Definition Language)<\/strong>: Commands like CREATE, ALTER and DROP that define or modify database structure. For example, creating a new table in a database involves a CREATE command.<\/li>\n\n\n\n<li><strong>DML (Data Manipulation Language)<\/strong>: Commands like INSERT, UPDATE and DELETE for modifying data. These commands interact directly with the rows of a table.<\/li>\n\n\n\n<li><strong>DQL (Data Query Language)<\/strong>: The SELECT statement used to query data. This command helps retrieve specific information from tables.<\/li>\n\n\n\n<li><strong>DCL (Data Control Language)<\/strong>: Commands like GRANT, REVOKE to control access to the database. They ensure data security.<\/li>\n\n\n\n<li><strong>TCL (Transaction Control Language)<\/strong>: Commands like COMMIT, ROLLBACK for managing transactions, ensuring data consistency.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-what-is-a-primary-key\"><strong>2. What is a primary key?<\/strong><\/h3>\n\n\n\n<p>A <strong>primary key<\/strong> is a unique identifier for a record in a table. It ensures that each row in the table is unique and cannot contain NULL values. It is the cornerstone of relational integrity. For example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE TABLE Employees (\n  EmployeeID INT PRIMARY KEY,\n  Name VARCHAR(50),\n  Department VARCHAR(50)\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"3-what-is-the-difference-between-where-and-having\"><strong>3. What is the difference between <\/strong><strong>WHERE<\/strong><strong> and <\/strong><strong>HAVING<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>WHERE<\/strong>: Filters rows before grouping data. It is used for raw data filtration.<\/li>\n\n\n\n<li><strong>HAVING<\/strong>: Filters groups after the GROUP BY clause, making it useful for aggregated data. Example:<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT Department, COUNT(*)\n\nFROM Employees\n\nWHERE Department IS NOT NULL\n\nGROUP BY Department\n\nHAVING COUNT(*) &gt; 5;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"4-what-is-a-foreign-key\"><strong>4. What is a foreign key?<\/strong><\/h3>\n\n\n\n<p>A <strong>foreign key<\/strong> is a field in one table that links to the primary key in another table. It enforces referential integrity between two tables, ensuring valid relationships. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE TABLE Orders (\n\n\u00a0\u00a0OrderID INT PRIMARY KEY,\n\n\u00a0\u00a0CustomerID INT,\n\n\u00a0\u00a0FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)\n\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"5-what-are-indexes-in-sql\"><strong>5. What are indexes in SQL?<\/strong><\/h3>\n\n\n\n<p><strong>Indexes<\/strong> are special lookup tables used to speed up data retrieval. They significantly improve query performance by allowing the database to find data without scanning every row in a table. However, they may slow down INSERT or UPDATE operations due to the maintenance of index data. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE INDEX idx_customer_name\n\nON Customers (CustomerName);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"6-explain-the-difference-between-delete-and-truncate\"><strong>6. Explain the difference between <\/strong><strong>DELETE<\/strong><strong> and <\/strong><strong>TRUNCATE<\/strong><strong>.<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DELETE<\/strong>: Removes specific rows based on a condition and can use a WHERE clause. It logs each row deleted.<\/li>\n\n\n\n<li><strong>TRUNCATE<\/strong>: Removes all rows from a table without logging individual row deletions, making it faster but less flexible. It resets table identity values.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7-what-is-the-use-of-the-group-by-clause\"><strong>7. What is the use of the <\/strong><strong>GROUP BY<\/strong><strong> clause?<\/strong><\/h3>\n\n\n\n<p>The <strong>GROUP BY<\/strong> clause is used to group rows with the same values in specified columns and perform aggregate functions like COUNT, SUM, or AVG on them. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT Department, AVG(Salary)\n\nFROM Employees\n\nGROUP BY Department;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"8-how-do-you-fetch-unique-records\"><strong>8. How do you fetch unique records?<\/strong><\/h3>\n\n\n\n<p>Use the DISTINCT keyword to fetch unique records. This ensures no duplicate rows are returned. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT DISTINCT Department\nFROM Employees;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"9-what-is-a-default-constraint-in-sql\"><strong>9. What is a default constraint in SQL?<\/strong><\/h3>\n\n\n\n<p>A <strong>default constraint<\/strong> sets a default value for a column if no value is specified during insertion. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE TABLE Products (\n\n\u00a0\u00a0ProductID INT,\n\n\u00a0\u00a0Price DECIMAL(10, 2) DEFAULT 0.00\n\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"10-explain-like-in-sql\"><strong>10. Explain <\/strong><strong>LIKE<\/strong><strong> in SQL.<\/strong><\/h3>\n\n\n\n<p>The <strong>LIKE<\/strong> operator is used for pattern matching in a WHERE clause. It is particularly useful for flexible searches. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT *\n\nFROM Employees\n\nWHERE Name LIKE &#039;A%&#039;;\n<\/pre><\/div>\n\n\n<p>This query retrieves all employees whose names start with 'A'.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intermediate-sql-interview-questions-with-detailed-answers\"><strong>Intermediate SQL interview questions with detailed answers:<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"11-find-customer-order-counts\"><strong>11. Find Customer Order Counts<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to list customers who have placed more than 5 orders. Use the customers and orders tables.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT c.customer_id, c.customer_name, COUNT(o.order_id) AS order_count\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nFROM customers c\n\nJOIN orders o ON c.customer_id = o.customer_id\n\nGROUP BY c.customer_id, c.customer_name\n\nHAVING COUNT(o.order_id) &gt; 5;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> This query joins the customers and orders tables on customer_id. It groups by customer_id and customer_name, then counts the number of orders for each customer. The HAVING clause filters the results to show customers with more than 5 orders.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"12-aggregate-functions-with-group-by\"><strong>12. Aggregate Functions with GROUP BY<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Calculate the total revenue, average revenue, and the count of orders grouped by product category in the sales table.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT product_category,\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SUM(revenue) AS total_revenue,\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0AVG(revenue) AS average_revenue,\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0COUNT(order_id) AS order_count\n\nFROM sales\n\nGROUP BY product_category;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> This query uses SUM() to calculate total revenue, AVG() to find the average revenue, and COUNT() to count the number of orders. The GROUP BY clause groups the result by product category.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"13-inner-join-practice\"><strong>13. INNER JOIN Practice<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Join the employees and departments tables. Return the employee name and department name for all employees.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT e.employee_name, d.department_name\n\nFROM employees e\n\nINNER JOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> An INNER JOIN is used to combine rows from employees and departments where the department_id matches in both tables. This returns the employee names along with their respective department names.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"14-subquery-for-average-salary\">1<strong>4. Subquery for Average Salary<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to find the names of employees who earn more than the average salary in the company.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_name\n\nFROM employees\n\nWHERE salary &gt; (SELECT AVG(salary) FROM employees);\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> The subquery (SELECT AVG(salary) FROM employees) calculates the average salary. The outer query returns employees whose salary is greater than this average.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"15-left-join-to-include-nulls\"><strong>15. LEFT JOIN to Include Nulls<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to list all employees and their department names, including employees who don't belong to any department.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT e.employee_name, d.department_name\n\nFROM employees e\n\nLEFT JOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> A LEFT JOIN is used here to include all employees. If an employee doesn't belong to a department, the result will show NULL for the department name.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"16-self-join-to-find-manager-employee-relationship\">1<strong>6. Self Join to Find Manager-Employee Relationship<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to list employees along with their manager's name. Assume there\u2019s a column manager_id in the employees table that points to another employee\u2019s employee_id.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT e.employee_name AS employee, m.employee_name AS manager\n\nFROM employees e\n\nLEFT JOIN employees m ON e.manager_id = m.employee_id;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> This is a self join on the employees table, where the manager_id in the employee record matches the employee_id in the manager\u2019s record. It returns the employee names along with their manager\u2019s names.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"17-using-union-to-combine-results\"><strong>17. Using UNION to Combine Results<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to list all employees and all customers (from the employees and customers tables) who have made orders. Ensure no duplicate records are returned.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_name AS name FROM employees\n\nUNION\n\nSELECT customer_name AS name FROM customers\n\nWHERE customer_id IN (SELECT DISTINCT customer_id FROM orders);\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> The UNION operator combines results from the employees and customers tables. The WHERE clause filters customers who have placed orders, ensuring unique names across both datasets.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"18-using-case-for-conditional-logic\"><strong>18. Using CASE for Conditional Logic<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to categorize employees based on their salary into \"High\", \"Medium\", and \"Low\" categories.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_name,\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0CASE\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WHEN salary &gt; 100000 THEN &#039;High&#039;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WHEN salary BETWEEN 50000 AND 100000 THEN &#039;Medium&#039;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ELSE &#039;Low&#039;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0END AS salary_category\n\nFROM employees;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> The CASE statement is used to categorize employees based on their salary. The result categorizes them as \"High\", \"Medium\", or \"Low\".<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"19-find-duplicate-records\"><strong>19. Find Duplicate Records<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to find duplicate email addresses from the users table. Assume the users table has a column email.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT email, COUNT(*) AS count\nFROM users\nGROUP BY email\nHAVING COUNT(*) &gt; 1;\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> This query groups records by email and counts how many times each email appears. The HAVING clause filters for emails that appear more than once.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"20-using-window-functions-row_number\"><strong>20. Using Window Functions (ROW_NUMBER)<\/strong><\/h3>\n\n\n\n<p><strong>Question:<\/strong><strong><br><\/strong>Write a query to assign a row number to each employee, ordered by their salary in descending order.<\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_name, salary,\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num\n\nFROM employees;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong> The ROW_NUMBER() window function assigns a unique row number to each row, ordered by salary in descending order. It doesn't require a GROUP BY clause because it is a window function operating over the entire result set.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advanced-sql-interview-questions\"><strong>Advanced SQL interview questions<\/strong><\/h2>\n\n\n\n<p>Here are <strong>15 advanced SQL interview questions or concepts<\/strong> with <strong>detailed answers<\/strong>, designed to test in-depth SQL knowledge and problem-solving ability:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"21-what-are-window-functions-explain-with-an-example\"><strong>21. What are Window Functions? Explain with an example.<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><strong>Window functions<\/strong> perform calculations across a set of table rows that are related to the current row. Unlike regular aggregate functions, which return a single value for a group of rows, window functions return a value for each row in the result set.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_name, salary,\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0RANK() OVER (ORDER BY salary DESC) AS rank\n\nFROM employees;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>RANK() is a window function that assigns a unique rank to each row within a result set, based on the salary column. The window is defined by the ORDER BY clause, and the rank restarts when there are ties in salary.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"22-what-is-the-difference-between-inner-join-left-join-and-right-join\"><strong>22. What is the difference between INNER JOIN, LEFT JOIN, and RIGHT JOIN?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>INNER JOIN<\/strong> returns only the rows that have matching values in both tables.<\/li>\n\n\n\n<li><strong>LEFT JOIN<\/strong> returns all rows from the left table and the matched rows from the right table. If there is no match, the result will contain NULL for columns from the right table.<\/li>\n\n\n\n<li><strong>RIGHT JOIN<\/strong> is similar to LEFT JOIN, but it returns all rows from the right table, and the matching rows from the left table. If there is no match, the result will contain NULL for columns from the left table.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"23-how-would-you-find-the-nth-highest-salary-in-a-table\"><strong>23. How would you find the Nth highest salary in a table?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>To find the Nth highest salary, you can use ROW_NUMBER() or RANK() along with a subquery or a CTE.<\/p>\n\n\n\n<p><strong>Example for Nth highest salary:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nWITH RankedSalaries AS (\n\n\u00a0\u00a0SELECT salary, RANK() OVER (ORDER BY salary DESC) AS rank\n\n\u00a0\u00a0FROM employees\n\n)\n\nSELECT salary\n\nFROM RankedSalaries\n\nWHERE rank = 3;\u00a0 -- Nth value, here it is the 3rd highest salary\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong><strong><br><\/strong>The RANK() function ranks salaries in descending order. By filtering for rank = 3, you get the 3rd highest salary.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"24-explain-the-concept-of-normalization-and-its-different-normal-forms\">2<strong>4. Explain the concept of Normalization and its different normal forms.<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><strong>Normalization<\/strong> is the process of organizing a database to reduce redundancy and dependency by splitting large tables into smaller, related tables. The goal is to eliminate undesirable characteristics like insertion, update, and deletion anomalies.<\/p>\n\n\n\n<p>The common <strong>normal forms (NF)<\/strong> are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1NF (First Normal Form):<\/strong> Ensures that each column contains atomic (indivisible) values and each row is unique.<\/li>\n\n\n\n<li><strong>2NF (Second Normal Form):<\/strong> Meets 1NF requirements and ensures that all non-key columns are fully dependent on the primary key.<\/li>\n\n\n\n<li><strong>3NF (Third Normal Form):<\/strong> Meets 2NF requirements and ensures that there are no transitive dependencies (i.e., non-key columns depend on other non-key columns).<\/li>\n\n\n\n<li><strong>BCNF (Boyce-Codd Normal Form):<\/strong> A stricter version of 3NF, where every determinant is a candidate key.<\/li>\n<\/ul>\n\n\n\n<p>Normalization helps in reducing data redundancy but might increase the complexity of queries, so in some cases, <strong>denormalization<\/strong> is used for performance reasons.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"25-what-is-a-common-table-expression-cte-and-how-is-it-different-from-a-subquery\"><strong>25. What is a Common Table Expression (CTE), and how is it different from a subquery?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A <strong>CTE<\/strong> is a temporary result set that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement. It is defined using the WITH keyword before the main query.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nWITH EmployeeCTE AS (\n\n\u00a0\u00a0SELECT employee_id, salary\n\n\u00a0\u00a0FROM employees\n\n\u00a0\u00a0WHERE department_id = 10\n\n)\n\nSELECT * FROM EmployeeCTE;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong><strong><br><\/strong>A <strong>CTE<\/strong> is similar to a subquery but can be more readable and reusable. It allows recursion and can be referenced multiple times in the main query.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"26-what-are-indexes-and-how-do-they-improve-query-performance\"><strong>26. What are Indexes and how do they improve query performance?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>An <strong>index<\/strong> is a database object that speeds up data retrieval operations on a table. Indexes are created on one or more columns and help the database engine quickly locate rows without scanning the entire table.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How they improve performance:<\/strong><strong><br><\/strong>Indexes reduce query execution time by allowing faster access to rows, especially for queries with WHERE, JOIN, or ORDER BY clauses. However, indexes can slow down INSERT, UPDATE, and DELETE operations because the index also needs to be updated.<\/li>\n\n\n\n<li><strong>Types of indexes:<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>B-tree index:<\/strong> Default index type, useful for range queries and equality searches.<\/li>\n\n\n\n<li><strong>Hash index:<\/strong> Used for equality comparisons.<\/li>\n\n\n\n<li><strong>Full-text index:<\/strong> Used for searching large text fields.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"27-what-is-the-difference-between-truncate-and-delete\"><strong>27. What is the difference between TRUNCATE and DELETE?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DELETE<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Removes rows from a table based on a condition.<\/li>\n\n\n\n<li>Slower because it logs each row deletion and maintains referential integrity (with foreign keys).<\/li>\n\n\n\n<li>Can be rolled back if wrapped in a transaction.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>TRUNCATE<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Removes all rows from a table, without logging each row individually.<\/li>\n\n\n\n<li>Faster than DELETE because it doesn\u2019t maintain transaction logs for each row.<\/li>\n\n\n\n<li>Cannot be rolled back (in most cases) and does not fire triggers.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"28-what-are-triggers-in-sql\"><strong>28. What are Triggers in SQL?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A <strong>trigger<\/strong> is a set of SQL statements that automatically execute or \"fire\" when certain events (INSERT, UPDATE, DELETE) occur on a table. Triggers are used for enforcing business rules, data validation, and auditing.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Example:<\/strong> A trigger can be set to track whenever a row is inserted into the employees table, automatically logging the action in an audit table.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"29-what-are-transaction-and-acid-properties\"><strong>29. What are Transaction and ACID properties?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A <strong>transaction<\/strong> is a sequence of one or more SQL operations that are executed as a single unit of work. Transactions ensure data integrity, even in the event of a failure.<\/p>\n\n\n\n<p><strong>ACID Properties:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Atomicity:<\/strong> Ensures that all operations in a transaction are completed successfully or none are.<\/li>\n\n\n\n<li><strong>Consistency:<\/strong> Ensures the database moves from one valid state to another.<\/li>\n\n\n\n<li><strong>Isolation:<\/strong> Ensures that operations of one transaction are not visible to others until the transaction is complete.<\/li>\n\n\n\n<li><strong>Durability:<\/strong> Ensures that once a transaction is committed, its changes are permanent.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"30-how-would-you-write-a-query-to-find-employees-who-worked-in-multiple-departments\"><strong>30. How would you write a query to find employees who worked in multiple departments?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>To find employees who worked in multiple departments, you can group by employee_id and count distinct department_id.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT employee_id, COUNT(DISTINCT department_id) AS department_count\n\nFROM employee_department\n\nGROUP BY employee_id\n\nHAVING COUNT(DISTINCT department_id) &gt; 1;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explanation:<\/strong><strong><br><\/strong>This query counts the number of distinct departments an employee has worked in, and filters those employees who have worked in more than one department.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"31-what-is-a-subquery-and-how-does-it-differ-from-a-join\"><strong>31. What is a Subquery and how does it differ from a Join?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A <strong>subquery<\/strong> is a query embedded within another query. It can be used to filter results or calculate values for comparison. A subquery is executed first, and its results are used by the outer query.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Difference from a <\/strong><strong>JOIN<\/strong><strong>:<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>Subquery:<\/strong> Runs a separate query and provides results to the main query.<\/li>\n\n\n\n<li><strong>JOIN:<\/strong> Combines rows from multiple tables based on a related column and executes in one step.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"32-explain-the-difference-between-group-by-and-distinct\"><strong>32. Explain the difference between GROUP BY and DISTINCT.<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GROUP BY<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Used to aggregate rows into groups based on one or more columns. It is often used with aggregate functions (like COUNT(), SUM(), AVG(), etc.).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>DISTINCT<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Used to remove duplicate rows from the result set, returning only unique values.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>Example for <\/strong><strong>GROUP BY<\/strong><strong>:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT department_id, COUNT(*) FROM employees GROUP BY department_id;\n<\/pre><\/div>\n\n\n<p><strong>Example for <\/strong><strong>DISTINCT<\/strong><strong>:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT DISTINCT department_id FROM employees;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"33-what-is-denormalization\"><strong>33. What is Denormalization?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><strong>Denormalization<\/strong> is the process of combining tables or adding redundant data to a database to improve read performance. It reduces the need for complex joins by storing the same data in multiple places, which can speed up queries at the cost of additional storage and potential data inconsistency.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"34-how-can-you-improve-the-performance-of-a-slow-query\"><strong>34. How can you improve the performance of a slow query?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>To improve query performance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use indexes<\/strong> on frequently queried columns.<\/li>\n\n\n\n<li><strong>Optimize joins<\/strong>: Avoid unnecessary joins and subqueries.<\/li>\n\n\n\n<li><strong>Rewrite subqueries<\/strong> as joins where possible.<\/li>\n\n\n\n<li><strong>Limit data<\/strong>: Only select the necessary columns, not SELECT *.<\/li>\n\n\n\n<li><strong>Use <\/strong><strong>EXPLAIN<\/strong> to analyze query plans and identify bottlenecks.<\/li>\n\n\n\n<li><strong>Avoid complex operations<\/strong> in WHERE clauses (e.g., functions on columns).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"35-what-is-cascading-in-foreign-keys\"><strong>35. What is Cascading in Foreign Keys?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><strong>Cascading<\/strong> is a set of rules that define what happens to related rows when a row in a referenced table is updated or deleted.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CASCADE<\/strong>: Automatically updates or deletes rows in the child table when the corresponding row in the parent table is updated or deleted.<\/li>\n\n\n\n<li><strong>SET NULL<\/strong>: Sets the foreign key values to NULL when the parent row is deleted.<\/li>\n\n\n\n<li><strong>NO ACTION<\/strong>: Prevents the update or delete operation if there are any related rows in the child table.<\/li>\n<\/ul>\n\n\n\n<p>These questions and concepts cover a broad range of advanced SQL topics such as window functions, joins, normalization, subqueries, and transaction management. Mastery of these areas will demonstrate a solid understanding of relational database systems and SQL performance optimization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tips-for-sql-interviews\"><strong>Tips for SQL Interviews<\/strong><\/h3>\n\n\n\n<p>Here are <strong>5-7 quick tips<\/strong> for succeeding in an <strong>SQL interview<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Master SQL Basics<\/strong>: Understand core concepts like SELECT, JOIN, GROUP BY, and aggregation functions.<\/li>\n\n\n\n<li><strong>Practice Regularly<\/strong>: Solve SQL problems on platforms like LeetCode, HackerRank, or SQLZoo to sharpen your skills.<\/li>\n\n\n\n<li><strong>Optimize Queries<\/strong>: Focus on writing efficient queries by using proper indexing and understanding query plans.<\/li>\n\n\n\n<li><strong>Know Advanced Concepts<\/strong>: Be prepared to discuss window functions, CTEs, normalization, and transaction management.<\/li>\n\n\n\n<li><strong>Think Aloud<\/strong>: During the interview, explain your thought process clearly when solving a problem.<\/li>\n\n\n\n<li><strong>Consider Edge Cases<\/strong>: Handle NULL values, empty sets, and duplicates in your queries to ensure robustness.<\/li>\n\n\n\n<li><strong>Stay Calm<\/strong>: Don't panic if you don't know the answer immediately\u2014focus on problem-solving steps and communicating your approach.<\/li>\n<\/ol>\n\n\n\n<p>These tips will help you prepare effectively and confidently tackle SQL interview challenges!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"enhance-your-sql-skills-with-free-courses\"><strong>Enhance Your SQL Skills with Free Courses<\/strong><\/h3>\n\n\n\n<p>Ready to take your SQL skills to the next level?&nbsp;<\/p>\n\n\n\n<p>If you're looking for structured learning to boost your SQL knowledge, check out <a href=\"https:\/\/www.mygreatlearning.com\/sql\/free-courses\"><strong>free SQL courses<\/strong><\/a><strong> <\/strong>to kickstart your learning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h3>\n\n\n\n<p>In SQL interviews, success comes from a combination of mastering core concepts, consistent practice, and a calm, structured approach to solving problems. By understanding key SQL operations, optimizing your queries, and being prepared to tackle complex scenarios, you'll be able to impress interviewers with both your technical skills and your problem-solving mindset.<\/p>\n\n\n\n<p>As you continue to refine your skills and knowledge, remember that consistent learning and practice are essential to staying ahead in the field. If you're ready to dive deeper and enhance your SQL expertise, consider exploring <a href=\"https:\/\/www.mygreatlearning.com\/sql\/free-courses\">free SQL courses <\/a>by Great Learning. These courses are designed to help you understand both basic and advanced concepts with hands-on experience, perfect for boosting your confidence in SQL interviews.<\/p>\n\n\n\n<p>Take a time to ace your practice on <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-editor-tool\/\">SQL Editor Tool<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get detailed answers to SQL interview questions covering key topics, tips, and tricks to showcase your expertise in database management.<\/p>\n","protected":false},"author":41,"featured_media":63585,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36844],"content_type":[36248],"class_list":["post-101820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-sql","content_type-career-guide"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>35+ SQL Interview Questions and Answers<\/title>\n<meta name=\"description\" content=\"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"35+ SQL Interview Questions and Answers\" \/>\n<meta property=\"og:description\" content=\"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-26T06:47:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-05T14:25:38+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1255\" \/>\n\t<meta property=\"og:image:height\" content=\"835\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"35+ SQL Interview Questions and Answers\",\"datePublished\":\"2024-11-26T06:47:50+00:00\",\"dateModified\":\"2024-12-05T14:25:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/\"},\"wordCount\":2763,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/iStock-1286560097.jpg\",\"keywords\":[\"sql\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/\",\"name\":\"35+ SQL Interview Questions and Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/iStock-1286560097.jpg\",\"datePublished\":\"2024-11-26T06:47:50+00:00\",\"dateModified\":\"2024-12-05T14:25:38+00:00\",\"description\":\"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/iStock-1286560097.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/iStock-1286560097.jpg\",\"width\":1255,\"height\":835,\"caption\":\"SQL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"35+ SQL Interview Questions and Answers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"35+ SQL Interview Questions and Answers","description":"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"35+ SQL Interview Questions and Answers","og_description":"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2024-11-26T06:47:50+00:00","article_modified_time":"2024-12-05T14:25:38+00:00","og_image":[{"width":1255,"height":835,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"35+ SQL Interview Questions and Answers","datePublished":"2024-11-26T06:47:50+00:00","dateModified":"2024-12-05T14:25:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/"},"wordCount":2763,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg","keywords":["sql"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/","name":"35+ SQL Interview Questions and Answers","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg","datePublished":"2024-11-26T06:47:50+00:00","dateModified":"2024-12-05T14:25:38+00:00","description":"Discover the most frequently asked SQL interview questions and answers. Perfect for both beginners and professionals to boost their preparation.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg","width":1255,"height":835,"caption":"SQL"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"35+ SQL Interview Questions and Answers"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg",1255,835,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-768x511.jpg",768,511,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-1024x681.jpg",1024,681,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg",1255,835,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097.jpg",1255,835,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-640x835.jpg",640,835,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/04\/iStock-1286560097-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Get detailed answers to SQL interview questions covering key topics, tips, and tricks to showcase your expertise in database management.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/101820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=101820"}],"version-history":[{"count":11,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/101820\/revisions"}],"predecessor-version":[{"id":107540,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/101820\/revisions\/107540"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/63585"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=101820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=101820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=101820"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=101820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}