{"id":6677,"date":"2025-05-02T12:19:12","date_gmt":"2025-05-02T12:19:12","guid":{"rendered":"https:\/\/www.hirist.tech\/blog\/?p=6677"},"modified":"2026-04-28T03:00:15","modified_gmt":"2026-04-28T03:00:15","slug":"top-100-sql-query-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/","title":{"rendered":"Top 100+ SQL Query Interview Questions and Answers"},"content":{"rendered":"\n<p>SQL queries are commands used to talk to a database. They first appeared in the 1970s when Donald D. Chamberlin and Raymond F. Boyce at IBM designed SQL to manage data in relational databases. Since then it has grown into the most common language for storing, retrieving and handling information. Many roles such as developers, testers, analysts and engineers use SQL every day. That is why interviewers ask SQL query questions to check practical skills.This blog includes the top 100+ most commonly asked SQL query interview questions, from beginner-level queries to tricky ones. Each answer is written in a way that is easy to understand and useful for interviews.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_SQL_Query\" title=\"What is SQL Query?\">What is SQL Query?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Query_Interview_Basics\" title=\"SQL Query Interview Basics\">SQL Query Interview Basics<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#1_Employees_Table\" title=\"1. Employees Table\">1. Employees Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#2_Orders_Table\" title=\"2. Orders Table\">2. Orders Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#3_Customers_Table\" title=\"3. Customers Table\">3. Customers Table<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Basic_SQL_Queries_for_Interview\" title=\"Basic SQL Queries for Interview\">Basic SQL Queries for Interview<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_does_the_SELECT_statement_do_in_SQL\" title=\"What does the SELECT statement do in SQL?\">What does the SELECT statement do in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_retrieve_unique_records_from_a_table\" title=\"How do you retrieve unique records from a table?\">How do you retrieve unique records from a table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_difference_between_WHERE_and_HAVING_clauses\" title=\"What is the difference between WHERE and HAVING clauses?\">What is the difference between WHERE and HAVING clauses?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_sort_records_in_SQL\" title=\"How do you sort records in SQL?\">How do you sort records in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_use_of_the_LIMIT_clause\" title=\"What is the use of the LIMIT clause?\">What is the use of the LIMIT clause?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_a_primary_key_in_SQL\" title=\"What is a primary key in SQL?\">What is a primary key in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_difference_between_UNION_and_UNION_ALL\" title=\"What is the difference between UNION and UNION ALL?\">What is the difference between UNION and UNION ALL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_fetch_customers_who_placed_orders_using_IN_and_EXISTS\" title=\"Write a query to fetch customers who placed orders using IN and EXISTS.\">Write a query to fetch customers who placed orders using IN and EXISTS.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_display_employee_and_manager_names_using_SELF_JOIN\" title=\"Write a query to display employee and manager names using SELF JOIN.\">Write a query to display employee and manager names using SELF JOIN.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_get_all_possible_combinations_of_employees_and_departments_using_CROSS_JOIN\" title=\"Write a query to get all possible combinations of employees and departments using CROSS JOIN.\">Write a query to get all possible combinations of employees and departments using CROSS JOIN.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_display_customers_who_have_placed_at_least_one_order_using_INNER_JOIN\" title=\"Write a query to display customers who have placed at least one order using INNER JOIN.\">Write a query to display customers who have placed at least one order using INNER JOIN.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_fetch_the_column_names_and_types_for_a_specific_table\" title=\"How do you fetch the column names and types for a specific table?\">How do you fetch the column names and types for a specific table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_aggregate_functions_in_SQL\" title=\"What are aggregate functions in SQL?\">What are aggregate functions in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_constraints_in_SQL_and_name_a_few_types\" title=\"What are constraints in SQL and name a few types?\">What are constraints in SQL and name a few types?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Intermediate_SQL_Query_Interview_Questions\" title=\"Intermediate SQL Query Interview Questions\">Intermediate SQL Query Interview Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_find_the_third_highest_salary_without_using_window_functions\" title=\"Write a query to find the third highest salary without using window functions.\">Write a query to find the third highest salary without using window functions.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_write_a_FULL_OUTER_JOIN_query\" title=\"How do you write a FULL OUTER JOIN query?\">How do you write a FULL OUTER JOIN query?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_find_gaps_in_sequential_invoice_IDs\" title=\"Write a query to find gaps in sequential invoice IDs.\">Write a query to find gaps in sequential invoice IDs.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_simulate_pivoting_department_data_without_using_the_PIVOT_operator\" title=\"Write a query to simulate pivoting department data without using the PIVOT operator.\">Write a query to simulate pivoting department data without using the PIVOT operator.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_difference_between_INNER_JOIN_LEFT_JOIN_RIGHT_JOIN_and_FULL_JOIN\" title=\"What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?\">What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_join_three_tables_and_filter_based_on_a_product_category\" title=\"Write a query to join three tables and filter based on a product category.\">Write a query to join three tables and filter based on a product category.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_using_SQL_joins_to_validate_data_mappings_between_a_source_and_target_table\" title=\"Write a query using SQL joins to validate data mappings between a source and target table.\">Write a query using SQL joins to validate data mappings between a source and target table.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_check_data_consistency_between_two_related_tables\" title=\"Write a query to check data consistency between two related tables.\">Write a query to check data consistency between two related tables.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_verify_the_record_count_between_a_source_and_a_target_table_during_testing\" title=\"Write a query to verify the record count between a source and a target table during testing.\">Write a query to verify the record count between a source and a target table during testing.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_SQL_query_to_compare_row-level_data_between_staging_and_target_tables\" title=\"Write a SQL query to compare row-level data between staging and target tables.\">Write a SQL query to compare row-level data between staging and target tables.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_test_transformation_logic_when_values_are_modified_or_derived\" title=\"Write a query to test transformation logic when values are modified or derived.\">Write a query to test transformation logic when values are modified or derived.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_check_for_NULLs_in_key_fields_after_transformation_is_complete\" title=\"Write a query to check for NULLs in key fields after transformation is complete.\">Write a query to check for NULLs in key fields after transformation is complete.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_validate_referential_integrity_between_parent_and_child_tables_in_a_data_pipeline\" title=\"Write a query to validate referential integrity between parent and child tables in a data pipeline.\">Write a query to validate referential integrity between parent and child tables in a data pipeline.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_rank_employees_by_salary_within_each_department\" title=\"Write a query to rank employees by salary within each department.\">Write a query to rank employees by salary within each department.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_fetch_the_top_2_highest_paid_employees_per_department\" title=\"Write a query to fetch the top 2 highest paid employees per department.\">Write a query to fetch the top 2 highest paid employees per department.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_a_transaction_in_SQL\" title=\"What is a transaction in SQL?\">What is a transaction in SQL?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Advanced_SQL_Queries_for_Interview\" title=\"Advanced SQL Queries for Interview\">Advanced SQL Queries for Interview<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_split_comma-separated_values_into_rows_in_SQL\" title=\"How do you split comma-separated values into rows in SQL?\">How do you split comma-separated values into rows in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_employees_table_write_a_SQL_query_to_transpose_department_names_into_columns_with_total_salary\" title=\"Using the employees table, write a SQL query to transpose department names into columns with total salary.\">Using the employees table, write a SQL query to transpose department names into columns with total salary.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_employees_table_find_employees_earning_more_than_the_average_salary_across_the_company\" title=\"Using the employees table, find employees earning more than the average salary across the company.\">Using the employees table, find employees earning more than the average salary across the company.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_orders_table_write_a_query_to_count_the_number_of_orders_placed_by_each_customer\" title=\"Using the orders table, write a query to count the number of orders placed by each customer.\">Using the orders table, write a query to count the number of orders placed by each customer.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_calculate_the_median_salary_of_employees\" title=\"Write a query to calculate the median salary of employees.\">Write a query to calculate the median salary of employees.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_calculate_the_90th_percentile_of_salaries\" title=\"How do you calculate the 90th percentile of salaries?\">How do you calculate the 90th percentile of salaries?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_recursive_query_to_display_the_employee_hierarchy_based_on_manager_relationships\" title=\"Write a recursive query to display the employee hierarchy based on manager relationships.\">Write a recursive query to display the employee hierarchy based on manager relationships.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_write_a_stored_procedure_to_update_multiple_tables\" title=\"How do you write a stored procedure to update multiple tables?\">How do you write a stored procedure to update multiple tables?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_use_IF%E2%80%A6ELSE_in_SQL_scripts\" title=\"How do you use IF\u2026ELSE in SQL scripts?\">How do you use IF\u2026ELSE in SQL scripts?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_temporary_tables_and_when_should_you_use_them\" title=\"What are temporary tables and when should you use them?\">What are temporary tables and when should you use them?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Query_Optimization_Tuning_Questions\" title=\"Query Optimization &amp; Tuning Questions\">Query Optimization &amp; Tuning Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Whats_the_impact_of_join_order_on_query_performance\" title=\"What&#8217;s the impact of join order on query performance?\">What&#8217;s the impact of join order on query performance?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_list_indexes_created_on_a_table\" title=\"How do you list indexes created on a table?\">How do you list indexes created on a table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-52\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_implement_concurrency_control_in_SQL\" title=\"How do you implement concurrency control in SQL?\">How do you implement concurrency control in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-53\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_the_properties_of_a_transaction_ACID_that_affect_performance\" title=\"What are the properties of a transaction (ACID) that affect performance?\">What are the properties of a transaction (ACID) that affect performance?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-54\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_views_and_how_are_they_used_for_simplifying_complex_queries\" title=\"What are views and how are they used for simplifying complex queries?\">What are views and how are they used for simplifying complex queries?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-55\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_test_transformation_logic_using_SQL_when_values_are_modified_or_derived\" title=\"How do you test transformation logic using SQL when values are modified or derived?\">How do you test transformation logic using SQL when values are modified or derived?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-56\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_can_filtering_early_and_joining_smaller_result_sets_improve_execution_time\" title=\"How can filtering early and joining smaller result sets improve execution time?\">How can filtering early and joining smaller result sets improve execution time?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-57\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Queries_Scenario-Based_Interview_Questions\" title=\"SQL Queries Scenario-Based Interview Questions\">SQL Queries Scenario-Based Interview Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-58\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_orders_table_write_a_query_to_calculate_the_running_total_of_order_amounts_by_customer\" title=\"Using the orders table, write a query to calculate the running total of order amounts by customer.\">Using the orders table, write a query to calculate the running total of order amounts by customer.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-59\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#From_the_orders_table_find_customers_who_placed_more_than_one_order\" title=\"From the orders table, find customers who placed more than one order.\">From the orders table, find customers who placed more than one order.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-60\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_customers_table_find_and_remove_duplicate_customer_records\" title=\"Using the customers table, find and remove duplicate customer records.\">Using the customers table, find and remove duplicate customer records.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-61\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_calculate_monthly_user_retention_using_order_or_login_data\" title=\"Write a query to calculate monthly user retention using order or login data.\">Write a query to calculate monthly user retention using order or login data.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-62\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_write_a_SQL_query_to_identify_user_churn_over_time\" title=\"How do you write a SQL query to identify user churn over time?\">How do you write a SQL query to identify user churn over time?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-63\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_can_you_identify_slowly_changing_dimension_SCD_changes_using_SQL\" title=\"How can you identify slowly changing dimension (SCD) changes using SQL?\">How can you identify slowly changing dimension (SCD) changes using SQL?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-64\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Tricky_SQL_Queries_for_Interview\" title=\"Tricky SQL Queries for Interview\">Tricky SQL Queries for Interview<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-65\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_orders_table_find_customers_who_didnt_place_an_order_in_the_last_30_days\" title=\"Using the orders table, find customers who didn&#8217;t place an order in the last 30 days.\">Using the orders table, find customers who didn&#8217;t place an order in the last 30 days.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-66\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Calculate_the_percentage_of_total_order_amount_contributed_by_each_region\" title=\"Calculate the percentage of total order amount contributed by each region.\">Calculate the percentage of total order amount contributed by each region.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-67\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_orders_table_write_a_query_to_find_the_number_of_days_between_order_date_and_today\" title=\"Using the orders table, write a query to find the number of days between order_date and today.\">Using the orders table, write a query to find the number of days between order_date and today.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-68\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_find_customers_who_have_placed_orders_in_all_regions\" title=\"Write a query to find customers who have placed orders in all regions.\">Write a query to find customers who have placed orders in all regions.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-69\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_orders_table_calculate_the_cumulative_percentage_of_sales_per_region\" title=\"Using the orders table, calculate the cumulative percentage of sales per region.\">Using the orders table, calculate the cumulative percentage of sales per region.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-70\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Using_the_employees_table_with_manager_id_flatten_the_reporting_hierarchy_using_a_recursive_CTE\" title=\"Using the employees table with manager_id, flatten the reporting hierarchy using a recursive CTE.\">Using the employees table with manager_id, flatten the reporting hierarchy using a recursive CTE.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-71\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Write_a_query_to_calculate_running_average_of_order_amount_by_customer\" title=\"Write a query to calculate running average of order amount by customer.\">Write a query to calculate running average of order amount by customer.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-72\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Queries_Interview_Questions_for_Freshers\" title=\"SQL Queries Interview Questions for Freshers\">SQL Queries Interview Questions for Freshers<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-73\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_SQL\" title=\"What is SQL?\">What is SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-74\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_an_SQL_query\" title=\"What is an SQL query?\">What is an SQL query?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-75\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_the_different_types_of_SQL_statements\" title=\"What are the different types of SQL statements?\">What are the different types of SQL statements?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-76\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_insert_data_into_a_table\" title=\"How do you insert data into a table?\">How do you insert data into a table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-77\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_difference_between_DELETE_and_TRUNCATE\" title=\"What is the difference between DELETE and TRUNCATE?\">What is the difference between DELETE and TRUNCATE?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-78\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_update_a_record_in_SQL\" title=\"How do you update a record in SQL?\">How do you update a record in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-79\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_the_purpose_of_the_GROUP_BY_clause\" title=\"What is the purpose of the GROUP BY clause?\">What is the purpose of the GROUP BY clause?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-80\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Interview_Queries_for_Experienced\" title=\"SQL Interview Queries for Experienced\">SQL Interview Queries for Experienced<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-81\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_optimize_a_slow-running_query\" title=\"How do you optimize a slow-running query?\">How do you optimize a slow-running query?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-82\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_is_a_correlated_subquery\" title=\"What is a correlated subquery?\">What is a correlated subquery?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-83\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_indexes_impact_query_performance\" title=\"How do indexes impact query performance?\">How do indexes impact query performance?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-84\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#What_are_window_functions_and_where_are_they_used\" title=\"What are window functions and where are they used?\">What are window functions and where are they used?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-85\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_do_you_debug_a_failing_SQL_query_in_production\" title=\"How do you debug a failing SQL query in production?\">How do you debug a failing SQL query in production?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-86\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Queries_Interview_Questions_for_2_Years_Experienced\" title=\"SQL Queries Interview Questions for 2 Years Experienced\">SQL Queries Interview Questions for 2 Years Experienced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-87\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Queries_Interview_Questions_for_3_Years_Experienced\" title=\"SQL Queries Interview Questions for 3 Years Experienced\">SQL Queries Interview Questions for 3 Years Experienced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-88\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Query_Interview_Questions_for_5_Years_Experienced\" title=\"SQL Query Interview Questions for 5 Years Experienced\">SQL Query Interview Questions for 5 Years Experienced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-89\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Query_Interview_Questions_for_7_Years_Experienced\" title=\"SQL Query Interview Questions for 7 Years Experienced\">SQL Query Interview Questions for 7 Years Experienced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-90\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Company-Specific_SQL_Query_Interview_Questions\" title=\"Company-Specific SQL Query Interview Questions\">Company-Specific SQL Query Interview Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-91\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Oracle_SQL_Query_Questions\" title=\"Oracle SQL Query Questions\">Oracle SQL Query Questions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-92\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Queries_for_Amazon_Interview\" title=\"SQL Queries for Amazon Interview\">SQL Queries for Amazon Interview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-93\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#TCS_Interview_Questions_on_SQL_Queries\" title=\"TCS Interview Questions on SQL Queries\">TCS Interview Questions on SQL Queries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-94\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Teradata_SQL_Queries_Interview_Questions\" title=\"Teradata SQL Queries Interview Questions\">Teradata SQL Queries Interview Questions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-95\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#SQL_Query_MCQs\" title=\"SQL Query MCQs\">SQL Query MCQs<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-96\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#1_Which_SQL_statement_is_used_to_fetch_data_from_a_database\" title=\"1. Which SQL statement is used to fetch data from a database?\">1. Which SQL statement is used to fetch data from a database?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-97\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#2_Which_of_the_following_clauses_is_used_with_aggregate_functions\" title=\"2. Which of the following clauses is used with aggregate functions?\">2. Which of the following clauses is used with aggregate functions?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-98\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#3_What_does_the_DISTINCT_keyword_do_in_SQL\" title=\"3. What does the DISTINCT keyword do in SQL?\">3. What does the DISTINCT keyword do in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-99\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#4_Which_SQL_command_removes_all_rows_but_keeps_the_table_structure\" title=\"4. Which SQL command removes all rows but keeps the table structure?\">4. Which SQL command removes all rows but keeps the table structure?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-100\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#5_What_is_the_default_sorting_order_in_SQL_when_using_ORDER_BY\" title=\"5. What is the default sorting order in SQL when using ORDER BY?\">5. What is the default sorting order in SQL when using ORDER BY?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-101\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#6_Which_JOIN_returns_only_matching_rows_between_two_tables\" title=\"6. Which JOIN returns only matching rows between two tables?\">6. Which JOIN returns only matching rows between two tables?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-102\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#7_Which_SQL_keyword_is_used_to_combine_the_result_of_two_SELECT_statements_while_removing_duplicates\" title=\"7. Which SQL keyword is used to combine the result of two SELECT statements while removing duplicates?\">7. Which SQL keyword is used to combine the result of two SELECT statements while removing duplicates?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-103\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#8_Which_of_the_following_is_a_valid_aggregate_function_in_SQL\" title=\"8. Which of the following is a valid aggregate function in SQL?\">8. Which of the following is a valid aggregate function in SQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-104\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#9_Which_constraint_ensures_that_a_column_cannot_have_NULL_values\" title=\"9. Which constraint ensures that a column cannot have NULL values?\">9. Which constraint ensures that a column cannot have NULL values?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-105\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#10_What_does_the_COUNT_function_return\" title=\"10. What does the COUNT(*) function return?\">10. What does the COUNT(*) function return?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-106\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#How_to_Prepare_for_SQL_Query_Interview_Questions\" title=\"How to Prepare for SQL Query Interview Questions?\">How to Prepare for SQL Query Interview Questions?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-107\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#Wrapping_Up\" title=\"Wrapping Up\">Wrapping Up<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-108\" href=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#FAQs\" title=\"FAQs\">FAQs<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_SQL_Query\"><\/span>What is SQL Query?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"558\" height=\"493\" src=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/What-is-sql-query.webp\" alt=\"SQL query\" class=\"wp-image-9689\" srcset=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/What-is-sql-query.webp 558w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/What-is-sql-query-300x265.webp 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Fun Fact:<\/strong> According to the Stack Overflow Developer Survey, 54.1% of professional developers reported using SQL. This shows how important SQL is for working with and managing data in real jobs.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> This list of top 100 SQL query interview questions is divided into different categories. It will help you go through the questions faster and find what you need easily.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Query_Interview_Basics\"><\/span>SQL Query Interview Basics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"683\" height=\"1024\" src=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details-683x1024.webp\" alt=\"SQL Query Interview Details\" class=\"wp-image-9691\" srcset=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details-683x1024.webp 683w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details-200x300.webp 200w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details-768x1152.webp 768w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details-585x878.webp 585w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-details.webp 1024w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> For better understanding and practical context, we will be using the following sample tables throughout the queries.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Employees_Table\"><\/span>1. Employees Table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>department<\/th><th>salary<\/th><th>manager_id<\/th><th>hire_date<\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>Alice<\/td><td>HR<\/td><td>50000<\/td><td>NULL<\/td><td>2020-01-15<\/td><\/tr><tr><td>102<\/td><td>Bob<\/td><td>IT<\/td><td>60000<\/td><td>101<\/td><td>2019-03-10<\/td><\/tr><tr><td>103<\/td><td>Carol<\/td><td>IT<\/td><td>65000<\/td><td>101<\/td><td>2021-07-01<\/td><\/tr><tr><td>104<\/td><td>David<\/td><td>Sales<\/td><td>55000<\/td><td>101<\/td><td>2022-11-20<\/td><\/tr><tr><td>105<\/td><td>Eve<\/td><td>Sales<\/td><td>54000<\/td><td>101<\/td><td>2023-06-05<\/td><\/tr><tr><td>106<\/td><td>Frank<\/td><td>IT<\/td><td>62000<\/td><td>102<\/td><td>2018-09-25<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Orders_Table\"><\/span>2. Orders Table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>order_id<\/th><th>customer_id<\/th><th>order_date<\/th><th>amount<\/th><th>region<\/th><\/tr><\/thead><tbody><tr><td>201<\/td><td>C001<\/td><td>2024-01-10<\/td><td>250<\/td><td>North<\/td><\/tr><tr><td>202<\/td><td>C002<\/td><td>2024-01-15<\/td><td>400<\/td><td>East<\/td><\/tr><tr><td>203<\/td><td>C001<\/td><td>2024-02-01<\/td><td>300<\/td><td>North<\/td><\/tr><tr><td>204<\/td><td>C003<\/td><td>2024-02-20<\/td><td>150<\/td><td>South<\/td><\/tr><tr><td>205<\/td><td>C004<\/td><td>2024-03-05<\/td><td>500<\/td><td>West<\/td><\/tr><tr><td>206<\/td><td>C002<\/td><td>2024-03-15<\/td><td>200<\/td><td>East<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Customers_Table\"><\/span>3. Customers Table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>name<\/th><th>city<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>John<\/td><td>Delhi<\/td><\/tr><tr><td>C002<\/td><td>Priya<\/td><td>Mumbai<\/td><\/tr><tr><td>C003<\/td><td>Ahmed<\/td><td>Bengaluru<\/td><\/tr><tr><td>C004<\/td><td>Sneha<\/td><td>Kolkata<\/td><\/tr><tr><td>C005<\/td><td>Ramesh<\/td><td>Hyderabad<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Basic_SQL_Queries_for_Interview\"><\/span>Basic SQL Queries for Interview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is a list of basic interview questions on SQL queries, along with their answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_does_the_SELECT_statement_do_in_SQL\"><\/span>What does the SELECT statement do in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The SELECT statement is used to fetch data from one or more tables in a database. You can choose specific columns or use * to select all columns.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name, department FROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>department<\/th><\/tr><\/thead><tbody><tr><td>Alice<\/td><td>HR<\/td><\/tr><tr><td>Bob<\/td><td>IT<\/td><\/tr><tr><td>Carol<\/td><td>IT<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_retrieve_unique_records_from_a_table\"><\/span>How do you retrieve unique records from a table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This is one of the most common basic SQL query interview questions you might come across.<\/p>\n\n\n\n<p>To remove duplicates, use the DISTINCT keyword. It ensures each value appears only once in the result.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT DISTINCT city FROM customers;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>city<\/th><\/tr><\/thead><tbody><tr><td>Delhi<\/td><\/tr><tr><td>Mumbai<\/td><\/tr><tr><td>Bengaluru<\/td><\/tr><tr><td>Kolkata<\/td><\/tr><tr><td>Hyderabad<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_WHERE_and_HAVING_clauses\"><\/span>What is the difference between WHERE and HAVING clauses?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>WHERE filters rows before aggregation; HAVING filters results after aggregation. WHERE works on raw data; HAVING works on grouped results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_sort_records_in_SQL\"><\/span>How do you sort records in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use ORDER BY to arrange results. By default, it sorts in ascending order. You can use DESC for descending.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name, salary \nFROM employees \nORDER BY salary DESC;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>salary<\/th><\/tr><\/thead><tbody><tr><td>Carol<\/td><td>65000<\/td><\/tr><tr><td>Frank<\/td><td>62000<\/td><\/tr><tr><td>Bob<\/td><td>60000<\/td><\/tr><tr><td>David<\/td><td>55000<\/td><\/tr><tr><td>Eve<\/td><td>54000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_use_of_the_LIMIT_clause\"><\/span>What is the use of the LIMIT clause?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>LIMIT controls how many rows appear in the result. It&#8217;s helpful when you want only a sample of data.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM orders LIMIT 3;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>order_id<\/th><th>customer_id<\/th><th>order_date<\/th><th>amount<\/th><th>region<\/th><\/tr><\/thead><tbody><tr><td>201<\/td><td>C001<\/td><td>2024-01-10<\/td><td>250<\/td><td>North<\/td><\/tr><tr><td>202<\/td><td>C002<\/td><td>2024-01-15<\/td><td>400<\/td><td>East<\/td><\/tr><tr><td>203<\/td><td>C001<\/td><td>2024-02-01<\/td><td>300<\/td><td>North<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_primary_key_in_SQL\"><\/span>What is a primary key in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A primary key uniquely identifies each row in a table. It must be unique and cannot be null. Each table can have only one primary key.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_UNION_and_UNION_ALL\"><\/span>What is the difference between UNION and UNION ALL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>UNION combines results from two queries and removes duplicates. UNION ALL combines results but keeps duplicates, making it faster.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- UNION (removes duplicates)\nSELECT city FROM customers\nUNION\nSELECT region FROM orders;\n\n-- UNION ALL (keeps duplicates)\nSELECT city FROM customers\nUNION ALL\nSELECT region FROM orders;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>city<\/th><\/tr><\/thead><tbody><tr><td>Delhi<\/td><\/tr><tr><td>Mumbai<\/td><\/tr><tr><td>North<\/td><\/tr><tr><td>East<\/td><\/tr><tr><td>South<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>With UNION, duplicate values like East appear only once. With UNION ALL, duplicates are kept.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_fetch_customers_who_placed_orders_using_IN_and_EXISTS\"><\/span>Write a query to fetch customers who placed orders using IN and EXISTS.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Both IN and EXISTS can be used to check if a customer has placed an order. IN compares values directly, while EXISTS checks for row existence in a subquery.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Using IN\nSELECT name \nFROM customers\nWHERE customer_id IN (SELECT customer_id FROM orders);\n\n-- Using EXISTS\nSELECT name\nFROM customers c\nWHERE EXISTS (\n  SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id\n);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><\/tr><\/thead><tbody><tr><td>John<\/td><\/tr><tr><td>Priya<\/td><\/tr><tr><td>Ahmed<\/td><\/tr><tr><td>Sneha<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_display_employee_and_manager_names_using_SELF_JOIN\"><\/span>Write a query to display employee and manager names using SELF JOIN.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A self-join is used when a table is joined with itself. Here, each employee is linked to their manager using manager_id.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT e.name AS employee, m.name AS manager\nFROM employees e\nJOIN employees m ON e.manager_id = m.emp_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>employee<\/th><th>manager<\/th><\/tr><\/thead><tbody><tr><td>Bob<\/td><td>Alice<\/td><\/tr><tr><td>Carol<\/td><td>Alice<\/td><\/tr><tr><td>David<\/td><td>Alice<\/td><\/tr><tr><td>Eve<\/td><td>Alice<\/td><\/tr><tr><td>Frank<\/td><td>Bob<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_get_all_possible_combinations_of_employees_and_departments_using_CROSS_JOIN\"><\/span>Write a query to get all possible combinations of employees and departments using CROSS JOIN.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A cross join pairs every row from one table with every row from another, giving all possible combinations.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT e.name, d.department\nFROM employees e\nCROSS JOIN (SELECT DISTINCT department FROM employees) d;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>department<\/th><\/tr><\/thead><tbody><tr><td>Alice<\/td><td>HR<\/td><\/tr><tr><td>Alice<\/td><td>IT<\/td><\/tr><tr><td>Alice<\/td><td>Sales<\/td><\/tr><tr><td>Bob<\/td><td>HR<\/td><\/tr><tr><td>Bob<\/td><td>IT<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_display_customers_who_have_placed_at_least_one_order_using_INNER_JOIN\"><\/span>Write a query to display customers who have placed at least one order using INNER JOIN.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>An inner join returns only the rows where there is a match in both tables, so only customers with orders appear in the result.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT c.customer_id, c.name, o.order_id\nFROM customers c\nINNER JOIN orders o ON c.customer_id = o.customer_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>name<\/th><th>order_id<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>John<\/td><td>201<\/td><\/tr><tr><td>C001<\/td><td>John<\/td><td>203<\/td><\/tr><tr><td>C002<\/td><td>Priya<\/td><td>202<\/td><\/tr><tr><td>C002<\/td><td>Priya<\/td><td>206<\/td><\/tr><tr><td>C003<\/td><td>Ahmed<\/td><td>204<\/td><\/tr><tr><td>C004<\/td><td>Sneha<\/td><td>205<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Only customers who actually placed orders appear. Customers with no orders (like Ramesh) are excluded.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"828\" height=\"828\" src=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join.webp\" alt=\"SQL Inner Join\" class=\"wp-image-9694\" srcset=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join.webp 828w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join-300x300.webp 300w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join-150x150.webp 150w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join-768x768.webp 768w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/SQL-inner-join-585x585.webp 585w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_fetch_the_column_names_and_types_for_a_specific_table\"><\/span>How do you fetch the column names and types for a specific table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can query the system catalog information_schema.columns to see column names and their data types.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT column_name, data_type \nFROM information_schema.columns \nWHERE table_name = 'employees';<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>column_name<\/th><th>data_type<\/th><\/tr><\/thead><tbody><tr><td>emp_id<\/td><td>integer<\/td><\/tr><tr><td>name<\/td><td>varchar<\/td><\/tr><tr><td>department<\/td><td>varchar<\/td><\/tr><tr><td>salary<\/td><td>numeric<\/td><\/tr><tr><td>hire_date<\/td><td>date<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_aggregate_functions_in_SQL\"><\/span>What are aggregate functions in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Aggregate functions perform calculations on a set of rows and return a single value.<\/p>\n\n\n\n<p><strong>Examples:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  COUNT(*) AS total_employees,\n  SUM(salary) AS total_salary,\n  AVG(salary) AS avg_salary,\n  MAX(salary) AS max_salary,\n  MIN(salary) AS min_salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>total_employees<\/th><th>total_salary<\/th><th>avg_salary<\/th><th>max_salary<\/th><th>min_salary<\/th><\/tr><\/thead><tbody><tr><td>6<\/td><td>346000<\/td><td>57667<\/td><td>65000<\/td><td>50000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_constraints_in_SQL_and_name_a_few_types\"><\/span>What are constraints in SQL and name a few types?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Constraints define rules on columns to maintain data integrity.<\/p>\n\n\n\n<ul>\n<li><strong>PRIMARY KEY<\/strong> \u2013 Uniquely identifies each row.<\/li>\n\n\n\n<li><strong>FOREIGN KEY<\/strong> \u2013 Ensures values match in another table.<\/li>\n\n\n\n<li><strong>NOT NULL<\/strong> \u2013 Column cannot be null.<\/li>\n\n\n\n<li><strong>UNIQUE<\/strong> \u2013 Ensures all values are different.<\/li>\n\n\n\n<li><strong>CHECK<\/strong> \u2013 Enforces a condition on values.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Basic SQL query-based interview questions often include simple commands, filtering, sorting, joins, and basic aggregations.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Intermediate_SQL_Query_Interview_Questions\"><\/span>Intermediate SQL Query Interview Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the commonly asked SQL query interview questions that go beyond the basics and test your practical problem-solving skills.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_find_the_third_highest_salary_without_using_window_functions\"><\/span>Write a query to find the third highest salary without using window functions.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To get the third highest, find the maximum salary that is less than the second highest salary (using nested subqueries).<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT MAX(salary) AS third_highest\nFROM employees\nWHERE salary &lt; (SELECT MAX(salary) \n                FROM employees \n                WHERE salary &lt; (SELECT MAX(salary) FROM employees));<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>third_highest<\/th><\/tr><\/thead><tbody><tr><td>60000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_write_a_FULL_OUTER_JOIN_query\"><\/span>How do you write a FULL OUTER JOIN query?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A full outer join returns all rows from both tables. If there is no match, NULL values are shown for missing columns.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT c.customer_id, c.name, o.order_id\nFROM customers c\nFULL OUTER JOIN orders o ON c.customer_id = o.customer_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>name<\/th><th>order_id<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>John<\/td><td>201<\/td><\/tr><tr><td>C001<\/td><td>John<\/td><td>203<\/td><\/tr><tr><td>C002<\/td><td>Priya<\/td><td>202<\/td><\/tr><tr><td>C002<\/td><td>Priya<\/td><td>206<\/td><\/tr><tr><td>C004<\/td><td>Sneha<\/td><td>205<\/td><\/tr><tr><td>C005<\/td><td>Ramesh<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_find_gaps_in_sequential_invoice_IDs\"><\/span>Write a query to find gaps in sequential invoice IDs.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>By checking if the next number (id + 1) exists in the table, you can find missing IDs in a sequence.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT id + 1 AS missing_id\nFROM invoices i\nWHERE NOT EXISTS (\n  SELECT 1 FROM invoices WHERE id = i.id + 1\n);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>missing_id<\/th><\/tr><\/thead><tbody><tr><td>104<\/td><\/tr><tr><td>109<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_simulate_pivoting_department_data_without_using_the_PIVOT_operator\"><\/span>Write a query to simulate pivoting department data without using the PIVOT operator.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can simulate pivoting by combining CASE expressions with aggregation functions like SUM().<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT department,\n       SUM(CASE WHEN salary &gt; 60000 THEN 1 ELSE 0 END) AS high_salary,\n       SUM(CASE WHEN salary &lt;= 60000 THEN 1 ELSE 0 END) AS low_salary\nFROM employees\nGROUP BY department;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>department<\/th><th>high_salary<\/th><th>low_salary<\/th><\/tr><\/thead><tbody><tr><td>HR<\/td><td>0<\/td><td>1<\/td><\/tr><tr><td>IT<\/td><td>2<\/td><td>1<\/td><\/tr><tr><td>Sales<\/td><td>0<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_INNER_JOIN_LEFT_JOIN_RIGHT_JOIN_and_FULL_JOIN\"><\/span>What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li><strong>INNER JOIN<\/strong> \u2013 returns only matching rows from both tables.<\/li>\n\n\n\n<li><strong>LEFT JOIN<\/strong> \u2013 returns all rows from the left table, and matching rows from the right (NULL if no match).<\/li>\n\n\n\n<li><strong>RIGHT JOIN<\/strong> \u2013 opposite of LEFT JOIN, keeps all rows from the right table.<\/li>\n\n\n\n<li><strong>FULL JOIN<\/strong> \u2013 returns all rows from both tables, with NULLs for missing matches.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_join_three_tables_and_filter_based_on_a_product_category\"><\/span>Write a query to join three tables and filter based on a product category.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Multi-table joins are used to connect related data. Here, we link customers \u2192 orders \u2192 products and filter for a category.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT c.name AS customer, p.product_name, p.category\nFROM customers c\nJOIN orders o ON c.customer_id = o.customer_id\nJOIN products p ON o.product_id = p.product_id\nWHERE p.category = 'Electronics';<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer<\/th><th>product_name<\/th><th>category<\/th><\/tr><\/thead><tbody><tr><td>John<\/td><td>Laptop<\/td><td>Electronics<\/td><\/tr><tr><td>Priya<\/td><td>Headphones<\/td><td>Electronics<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_using_SQL_joins_to_validate_data_mappings_between_a_source_and_target_table\"><\/span>Write a query using SQL joins to validate data mappings between a source and target table.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This is used in testing to make sure values match after migration or ETL.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT s.id, s.name, t.name AS target_name\nFROM source_table s\nJOIN target_table t ON s.id = t.id\nWHERE s.name &lt;&gt; t.name;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>name<\/th><th>target_name<\/th><\/tr><\/thead><tbody><tr><td>102<\/td><td>Bob<\/td><td>Bobby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_check_data_consistency_between_two_related_tables\"><\/span>Write a query to check data consistency between two related tables.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use EXCEPT or NOT EXISTS to find mismatches between tables.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT id, status FROM source_table\nEXCEPT\nSELECT id, status FROM target_table;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>status<\/th><\/tr><\/thead><tbody><tr><td>110<\/td><td>Active<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_verify_the_record_count_between_a_source_and_a_target_table_during_testing\"><\/span>Write a query to verify the record count between a source and a target table during testing.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Comparing counts is a quick way to check if rows match after ETL loads.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  (SELECT COUNT(*) FROM source_table) AS source_count,\n  (SELECT COUNT(*) FROM target_table) AS target_count;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>source_count<\/th><th>target_count<\/th><\/tr><\/thead><tbody><tr><td>1000<\/td><td>1000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_SQL_query_to_compare_row-level_data_between_staging_and_target_tables\"><\/span>Write a SQL query to compare row-level data between staging and target tables.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use FULL OUTER JOIN to identify mismatched or missing records.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT *\nFROM staging s\nFULL OUTER JOIN final f ON s.id = f.id\nWHERE s.value &lt;&gt; f.value OR s.value IS NULL OR f.value IS NULL;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>s.value<\/th><th>f.value<\/th><\/tr><\/thead><tbody><tr><td>205<\/td><td>NULL<\/td><td>Active<\/td><\/tr><tr><td>210<\/td><td>Inactive<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_test_transformation_logic_when_values_are_modified_or_derived\"><\/span>Write a query to test transformation logic when values are modified or derived.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Apply transformation rules manually and compare with the target.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT id, source_value, source_value * 1.1 AS expected, transformed_value\nFROM target_table\nWHERE ROUND(source_value * 1.1, 2) &lt;&gt; transformed_value;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>source_value<\/th><th>expected<\/th><th>transformed_value<\/th><\/tr><\/thead><tbody><tr><td>301<\/td><td>200<\/td><td>220.00<\/td><td>219.50<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_check_for_NULLs_in_key_fields_after_transformation_is_complete\"><\/span>Write a query to check for NULLs in key fields after transformation is complete.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Key fields should never be NULL after loading, so this check is mandatory.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT *\nFROM final_table\nWHERE key_column IS NULL OR date_field IS NULL;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>key_column<\/th><th>date_field<\/th><th>value<\/th><\/tr><\/thead><tbody><tr><td>NULL<\/td><td>2024-01-01<\/td><td>Test<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_validate_referential_integrity_between_parent_and_child_tables_in_a_data_pipeline\"><\/span>Write a query to validate referential integrity between parent and child tables in a data pipeline.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT *\nFROM child_table c\nWHERE c.parent_id NOT IN (SELECT id FROM parent_table);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>parent_id<\/th><th>child_value<\/th><\/tr><\/thead><tbody><tr><td>999<\/td><td>Test Row<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_rank_employees_by_salary_within_each_department\"><\/span>Write a query to rank employees by salary within each department.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use DENSE_RANK() with PARTITION BY to rank within groups.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name, department, salary,\n       DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>department<\/th><th>salary<\/th><th>rank<\/th><\/tr><\/thead><tbody><tr><td>Carol<\/td><td>IT<\/td><td>65000<\/td><td>1<\/td><\/tr><tr><td>Frank<\/td><td>IT<\/td><td>62000<\/td><td>2<\/td><\/tr><tr><td>Bob<\/td><td>IT<\/td><td>60000<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_fetch_the_top_2_highest_paid_employees_per_department\"><\/span>Write a query to fetch the top 2 highest paid employees per department.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use ranking with a filter on rank value.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM (\n  SELECT name, department, salary,\n         RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk\n  FROM employees\n) t\nWHERE rnk &lt;= 2;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>department<\/th><th>salary<\/th><th>rnk<\/th><\/tr><\/thead><tbody><tr><td>Carol<\/td><td>IT<\/td><td>65000<\/td><td>1<\/td><\/tr><tr><td>Frank<\/td><td>IT<\/td><td>62000<\/td><td>2<\/td><\/tr><tr><td>Bob<\/td><td>IT<\/td><td>60000<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_transaction_in_SQL\"><\/span>What is a transaction in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A transaction is a sequence of operations performed as a single logical unit. It guarantees either all steps succeed or none do.<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-25-postgresql-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 25+ PostgreSQL Interview Questions and Answers<\/a><\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advanced_SQL_Queries_for_Interview\"><\/span>Advanced SQL Queries for Interview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let&#8217;s go through some advanced SQL query interview questions and answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_split_comma-separated_values_into_rows_in_SQL\"><\/span>How do you split comma-separated values into rows in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use built-in string-splitting functions to convert a CSV string into multiple rows.<\/p>\n\n\n\n<p><strong>Input (PostgreSQL):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT unnest(string_to_array('A,B,C', ',')) AS item;<\/code><\/pre>\n\n\n\n<p><strong>Input (SQL Server):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT value FROM STRING_SPLIT('A,B,C', ',');<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>item<\/th><\/tr><\/thead><tbody><tr><td>A<\/td><\/tr><tr><td>B<\/td><\/tr><tr><td>C<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-50-sql-server-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 50+ SQL Server Interview Questions and Answers<\/a><\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_employees_table_write_a_SQL_query_to_transpose_department_names_into_columns_with_total_salary\"><\/span>Using the employees table, write a SQL query to transpose department names into columns with total salary.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use CASE with SUM() to pivot rows into department-wise salary totals.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n  SUM(CASE WHEN department = 'HR' THEN salary ELSE 0 END) AS HR_Salary,\n  SUM(CASE WHEN department = 'IT' THEN salary ELSE 0 END) AS IT_Salary,\n  SUM(CASE WHEN department = 'Sales' THEN salary ELSE 0 END) AS Sales_Salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>HR_Salary<\/th><th>IT_Salary<\/th><th>Sales_Salary<\/th><\/tr><\/thead><tbody><tr><td>50000<\/td><td>187000<\/td><td>109000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_employees_table_find_employees_earning_more_than_the_average_salary_across_the_company\"><\/span>Using the employees table, find employees earning more than the average salary across the company.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Compare each employee&#8217;s salary with the overall average salary using a subquery.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT emp_id, name, salary\nFROM employees\nWHERE salary &gt; (SELECT AVG(salary) FROM employees);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>salary<\/th><\/tr><\/thead><tbody><tr><td>103<\/td><td>Carol<\/td><td>65000<\/td><\/tr><tr><td>106<\/td><td>Frank<\/td><td>62000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_orders_table_write_a_query_to_count_the_number_of_orders_placed_by_each_customer\"><\/span>Using the orders table, write a query to count the number of orders placed by each customer.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use COUNT() with GROUP BY to get order counts per customer.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id, COUNT(*) AS total_orders\nFROM orders\nGROUP BY customer_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>total_orders<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>2<\/td><\/tr><tr><td>C002<\/td><td>2<\/td><\/tr><tr><td>C003<\/td><td>1<\/td><\/tr><tr><td>C004<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_calculate_the_median_salary_of_employees\"><\/span>Write a query to calculate the median salary of employees.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Median is the middle salary, calculated using PERCENTILE_CONT(0.5).<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>median_salary<\/th><\/tr><\/thead><tbody><tr><td>57000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_calculate_the_90th_percentile_of_salaries\"><\/span>How do you calculate the 90th percentile of salaries?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The 90th percentile shows the salary above which only 10% earn.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY salary) AS p90_salary\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>p90_salary<\/th><\/tr><\/thead><tbody><tr><td>64500<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_recursive_query_to_display_the_employee_hierarchy_based_on_manager_relationships\"><\/span>Write a recursive query to display the employee hierarchy based on manager relationships.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Recursive CTE builds hierarchy by linking employees to their managers.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WITH RECURSIVE emp_hierarchy AS (\n    SELECT emp_id, name, manager_id, 1 AS level\n    FROM employees\n    WHERE manager_id IS NULL\n    UNION ALL\n    SELECT e.emp_id, e.name, e.manager_id, h.level + 1\n    FROM employees e\n    JOIN emp_hierarchy h ON e.manager_id = h.emp_id\n)\nSELECT * FROM emp_hierarchy;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>manager_id<\/th><th>level<\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>Alice<\/td><td>NULL<\/td><td>1<\/td><\/tr><tr><td>102<\/td><td>Bob<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>103<\/td><td>Carol<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>104<\/td><td>David<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>105<\/td><td>Eve<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>106<\/td><td>Frank<\/td><td>102<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_write_a_stored_procedure_to_update_multiple_tables\"><\/span>How do you write a stored procedure to update multiple tables?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A stored procedure groups multiple SQL statements for reuse and consistency.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE PROCEDURE update_data()\nBEGIN\n   UPDATE orders SET amount = amount + 50 WHERE order_id = 201;\n   UPDATE customers SET city = 'Delhi' WHERE customer_id = 'C001';\nEND;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_use_IF%E2%80%A6ELSE_in_SQL_scripts\"><\/span>How do you use IF\u2026ELSE in SQL scripts?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use conditional logic to execute different statements based on conditions.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IF (SELECT AVG(salary) FROM employees) &gt; 60000\n   PRINT 'High average salary'\nELSE\n   PRINT 'Normal average salary';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_temporary_tables_and_when_should_you_use_them\"><\/span>What are temporary tables and when should you use them?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Temporary tables store intermediate results for session use, helpful in complex queries.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMPORARY TABLE temp_emps AS\nSELECT name, salary FROM employees WHERE salary &gt; 60000;<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Each SQL question and answer here is designed to test advanced-level concepts in interviews.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Query_Optimization_Tuning_Questions\"><\/span>Query Optimization &amp; Tuning Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the frequently asked SQL optimization questions that test how well you understand performance, indexing, and query tuning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Whats_the_impact_of_join_order_on_query_performance\"><\/span>What&#8217;s the impact of join order on query performance?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The join order affects how many rows are processed. Filtering early and joining smaller sets improves speed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_list_indexes_created_on_a_table\"><\/span>How do you list indexes created on a table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Indexes speed up queries. Use catalog views to see indexes.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT indexname, indexdef \nFROM pg_indexes \nWHERE tablename = 'employees';<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>indexname<\/th><th>indexdef<\/th><\/tr><\/thead><tbody><tr><td>employees_pkey<\/td><td>CREATE UNIQUE INDEX employees_pkey ON employees(emp_id)<\/td><\/tr><tr><td>emp_dept_idx<\/td><td>CREATE INDEX emp_dept_idx ON employees(department)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_implement_concurrency_control_in_SQL\"><\/span>How do you implement concurrency control in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use transaction isolation levels (READ COMMITTED, SERIALIZABLE) and locks to avoid conflicts in multi-user environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_the_properties_of_a_transaction_ACID_that_affect_performance\"><\/span>What are the properties of a transaction (ACID) that affect performance?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li><strong>Atomicity<\/strong> \u2013 rollback adds overhead.<\/li>\n\n\n\n<li><strong>Consistency<\/strong> \u2013 constraints can slow inserts.<\/li>\n\n\n\n<li><strong>Isolation<\/strong> \u2013 higher levels mean more locking.<\/li>\n\n\n\n<li><strong>Durability<\/strong> \u2013 logging ensures safety but impacts write speed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_views_and_how_are_they_used_for_simplifying_complex_queries\"><\/span>What are views and how are they used for simplifying complex queries?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Views are saved queries that simplify joins and filters. They improve readability but may affect performance if nested.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE VIEW high_salary_emps AS\nSELECT name, salary FROM employees WHERE salary &gt; 60000;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_test_transformation_logic_using_SQL_when_values_are_modified_or_derived\"><\/span>How do you test transformation logic using SQL when values are modified or derived?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Apply the same formula manually and compare results with transformed values.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT id, source_value, source_value * 1.1 AS expected, transformed_value\nFROM target_table\nWHERE ROUND(source_value * 1.1, 2) &lt;&gt; transformed_value;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>source_value<\/th><th>expected<\/th><th>transformed_value<\/th><\/tr><\/thead><tbody><tr><td>301<\/td><td>200<\/td><td>220.00<\/td><td>219.50<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_can_filtering_early_and_joining_smaller_result_sets_improve_execution_time\"><\/span>How can filtering early and joining smaller result sets improve execution time?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Filtering reduces data scanned, so joins run faster. It avoids unnecessary processing on large datasets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Queries_Scenario-Based_Interview_Questions\"><\/span>SQL Queries Scenario-Based Interview Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>These are some scenario-based SQL queries interview questions with answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_orders_table_write_a_query_to_calculate_the_running_total_of_order_amounts_by_customer\"><\/span>Using the orders table, write a query to calculate the running total of order amounts by customer.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use the SUM() window function to keep a cumulative total ordered by date per customer.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id, order_date, amount,\n       SUM(amount) OVER (PARTITION BY customer_id ORDER BY order_date) AS running_total\nFROM orders;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>order_date<\/th><th>amount<\/th><th>running_total<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>2024-01-10<\/td><td>250<\/td><td>250<\/td><\/tr><tr><td>C001<\/td><td>2024-02-01<\/td><td>300<\/td><td>550<\/td><\/tr><tr><td>C002<\/td><td>2024-01-15<\/td><td>400<\/td><td>400<\/td><\/tr><tr><td>C002<\/td><td>2024-03-15<\/td><td>200<\/td><td>600<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"From_the_orders_table_find_customers_who_placed_more_than_one_order\"><\/span>From the orders table, find customers who placed more than one order.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use GROUP BY with HAVING to filter customers with order counts greater than one.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id\nFROM orders\nGROUP BY customer_id\nHAVING COUNT(*) &gt; 1;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><\/tr><tr><td>C002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_customers_table_find_and_remove_duplicate_customer_records\"><\/span>Using the customers table, find and remove duplicate customer records.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>First, identify duplicates using GROUP BY. Then remove extra rows with ROW_NUMBER().<\/p>\n\n\n\n<p><strong>Input (to identify):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name, city, COUNT(*) \nFROM customers\nGROUP BY name, city\nHAVING COUNT(*) &gt; 1;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>city<\/th><th>count<\/th><\/tr><\/thead><tbody><tr><td>John<\/td><td>Delhi<\/td><td>2<\/td><\/tr><tr><td>Priya<\/td><td>Mumbai<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Input (to remove duplicates):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE FROM customers\nWHERE customer_id NOT IN (\n   SELECT customer_id FROM (\n       SELECT customer_id,\n              ROW_NUMBER() OVER (PARTITION BY name, city ORDER BY customer_id) AS rn\n       FROM customers\n   ) t WHERE rn = 1\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_calculate_monthly_user_retention_using_order_or_login_data\"><\/span>Write a query to calculate monthly user retention using order or login data.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use a self-join on users across months to check if they return in the following month.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a.user_id, a.login_month, b.login_month AS retained_month\nFROM logins a\nJOIN logins b ON a.user_id = b.user_id\nWHERE a.login_month = '2024-01' \n  AND b.login_month = '2024-02';<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>user_id<\/th><th>login_month<\/th><th>retained_month<\/th><\/tr><\/thead><tbody><tr><td>U001<\/td><td>2024-01<\/td><td>2024-02<\/td><\/tr><tr><td>U004<\/td><td>2024-01<\/td><td>2024-02<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_write_a_SQL_query_to_identify_user_churn_over_time\"><\/span>How do you write a SQL query to identify user churn over time?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Churned users are those with only one recorded activity or no activity after a certain date.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT user_id\nFROM activity\nGROUP BY user_id\nHAVING COUNT(*) = 1;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>user_id<\/th><\/tr><\/thead><tbody><tr><td>U003<\/td><\/tr><tr><td>U007<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_can_you_identify_slowly_changing_dimension_SCD_changes_using_SQL\"><\/span>How can you identify slowly changing dimension (SCD) changes using SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Compare current vs. historical data to find attribute changes where old records are still active.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT h.id, h.address AS old_address, c.address AS new_address\nFROM history_table h\nJOIN current_table c ON h.id = c.id\nWHERE h.address &lt;&gt; c.address \n  AND h.end_date IS NULL;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>old_address<\/th><th>new_address<\/th><\/tr><\/thead><tbody><tr><td>105<\/td><td>Delhi<\/td><td>Gurugram<\/td><\/tr><tr><td>109<\/td><td>Bangalore<\/td><td>Hyderabad<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Scenario-based SQL queries questions for interview often test your problem-solving skills and real-world understanding.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tricky_SQL_Queries_for_Interview\"><\/span>Tricky SQL Queries for Interview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is a list of tricky SQL queries interview questions and their answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_orders_table_find_customers_who_didnt_place_an_order_in_the_last_30_days\"><\/span>Using the orders table, find customers who didn&#8217;t place an order in the last 30 days.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use NOT IN with a subquery to filter out customers who recently ordered.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id\nFROM customers\nWHERE customer_id NOT IN (\n  SELECT customer_id\n  FROM orders\n  WHERE order_date &gt;= CURRENT_DATE - INTERVAL '30 days'\n);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><\/tr><\/thead><tbody><tr><td>C004<\/td><\/tr><tr><td>C007<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Calculate_the_percentage_of_total_order_amount_contributed_by_each_region\"><\/span>Calculate the percentage of total order amount contributed by each region.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use SUM() with window functions to compute percentage share by region.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT region,\n       SUM(amount) AS total,\n       ROUND(SUM(amount) * 100.0 \/ SUM(SUM(amount)) OVER(), 2) AS percentage\nFROM orders\nGROUP BY region;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>region<\/th><th>total<\/th><th>percentage<\/th><\/tr><\/thead><tbody><tr><td>North<\/td><td>1200<\/td><td>30.00<\/td><\/tr><tr><td>South<\/td><td>1800<\/td><td>45.00<\/td><\/tr><tr><td>West<\/td><td>1000<\/td><td>25.00<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_orders_table_write_a_query_to_find_the_number_of_days_between_order_date_and_today\"><\/span>Using the orders table, write a query to find the number of days between order_date and today.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use date arithmetic to subtract order_date from the current date.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT order_id, customer_id, \n       CURRENT_DATE - order_date AS days_since_order\nFROM orders;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>order_id<\/th><th>customer_id<\/th><th>days_since_order<\/th><\/tr><\/thead><tbody><tr><td>201<\/td><td>C001<\/td><td>45<\/td><\/tr><tr><td>202<\/td><td>C002<\/td><td>30<\/td><\/tr><tr><td>203<\/td><td>C001<\/td><td>10<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_find_customers_who_have_placed_orders_in_all_regions\"><\/span>Write a query to find customers who have placed orders in all regions.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You might also come across complex SQL queries interview questions like this one. Use HAVING COUNT(DISTINCT region) equal to total distinct regions in orders.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id\nFROM orders\nGROUP BY customer_id\nHAVING COUNT(DISTINCT region) = (SELECT COUNT(DISTINCT region) FROM orders);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><\/tr><tr><td>C004<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Tricky SQL-based interview questions are often asked in technical rounds to assess logical thinking and query skills.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_orders_table_calculate_the_cumulative_percentage_of_sales_per_region\"><\/span>Using the orders table, calculate the cumulative percentage of sales per region.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use a window function with SUM() to get cumulative totals and divide by overall sales.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT region, amount,\n       SUM(amount) OVER (PARTITION BY region ORDER BY order_date) * 100.0 \/ SUM(amount) OVER() AS cumulative_pct\nFROM orders;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>region<\/th><th>amount<\/th><th>cumulative_pct<\/th><\/tr><\/thead><tbody><tr><td>North<\/td><td>250<\/td><td>5.5<\/td><\/tr><tr><td>North<\/td><td>300<\/td><td>12.1<\/td><\/tr><tr><td>East<\/td><td>400<\/td><td>21.0<\/td><\/tr><tr><td>East<\/td><td>200<\/td><td>25.5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_employees_table_with_manager_id_flatten_the_reporting_hierarchy_using_a_recursive_CTE\"><\/span>Using the employees table with manager_id, flatten the reporting hierarchy using a recursive CTE.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A recursive CTE retrieves all employee-manager relationships and levels in the hierarchy.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WITH RECURSIVE hierarchy AS (\n  SELECT emp_id, name, manager_id, 1 AS level\n  FROM employees\n  WHERE manager_id IS NULL\n  UNION ALL\n  SELECT e.emp_id, e.name, e.manager_id, h.level + 1\n  FROM employees e\n  JOIN hierarchy h ON e.manager_id = h.emp_id\n)\nSELECT * FROM hierarchy;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>manager_id<\/th><th>level<\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>Alice<\/td><td>NULL<\/td><td>1<\/td><\/tr><tr><td>102<\/td><td>Bob<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>103<\/td><td>Carol<\/td><td>101<\/td><td>2<\/td><\/tr><tr><td>106<\/td><td>Frank<\/td><td>102<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_query_to_calculate_running_average_of_order_amount_by_customer\"><\/span>Write a query to calculate running average of order amount by customer.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use AVG() as a window function ordered by order_date for each customer.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT customer_id, order_date,\n       AVG(amount) OVER (PARTITION BY customer_id ORDER BY order_date) AS running_avg\nFROM orders;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>customer_id<\/th><th>order_date<\/th><th>running_avg<\/th><\/tr><\/thead><tbody><tr><td>C001<\/td><td>2024-01-10<\/td><td>250<\/td><\/tr><tr><td>C001<\/td><td>2024-02-01<\/td><td>275<\/td><\/tr><tr><td>C002<\/td><td>2024-01-15<\/td><td>400<\/td><\/tr><tr><td>C002<\/td><td>2024-03-15<\/td><td>300<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Complex SQL queries questions for interview often focus on nested queries, advanced joins, and performance logic.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Queries_Interview_Questions_for_Freshers\"><\/span>SQL Queries Interview Questions for Freshers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some frequently asked interview questions on SQL queries and their answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_SQL\"><\/span>What is SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>SQL (Structured Query Language) is a standard programming language used to manage and work with relational databases. It allows you to create, read, update, and delete data stored in tables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_an_SQL_query\"><\/span>What is an SQL query?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>An SQL query is a command written in SQL to perform an action on a database \u2013 like retrieving data, updating records, or deleting rows. For example, <code>SELECT * FROM users;<\/code> is a query to fetch all user records.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_the_different_types_of_SQL_statements\"><\/span>What are the different types of SQL statements?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>SQL statements fall into categories like:<\/p>\n\n\n\n<ul>\n<li><strong>DML (Data Manipulation Language):<\/strong> SELECT, INSERT, UPDATE, DELETE<\/li>\n\n\n\n<li><strong>DDL (Data Definition Language):<\/strong> CREATE, ALTER, DROP<\/li>\n\n\n\n<li><strong>DCL (Data Control Language):<\/strong> GRANT, REVOKE<\/li>\n\n\n\n<li><strong>TCL (Transaction Control Language):<\/strong> COMMIT, ROLLBACK, SAVEPOINT<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_insert_data_into_a_table\"><\/span>How do you insert data into a table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use the INSERT INTO statement to add new rows.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO employees (emp_id, name, department, salary)\nVALUES (107, 'George', 'Finance', 58000);<\/code><\/pre>\n\n\n\n<p><strong>Output (new row added):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>department<\/th><th>salary<\/th><\/tr><\/thead><tbody><tr><td>107<\/td><td>George<\/td><td>Finance<\/td><td>58000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_DELETE_and_TRUNCATE\"><\/span>What is the difference between DELETE and TRUNCATE?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>DELETE removes specific rows based on a condition and can be rolled back. TRUNCATE removes all rows quickly but can&#8217;t be rolled back in most systems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_update_a_record_in_SQL\"><\/span>How do you update a record in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Use the UPDATE statement with a WHERE clause to modify specific rows.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE employees\nSET salary = 60000\nWHERE emp_id = 102;<\/code><\/pre>\n\n\n\n<p><strong>Output (after update):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>emp_id<\/th><th>name<\/th><th>department<\/th><th>salary<\/th><\/tr><\/thead><tbody><tr><td>102<\/td><td>Bob<\/td><td>IT<\/td><td>60000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_purpose_of_the_GROUP_BY_clause\"><\/span>What is the purpose of the GROUP BY clause?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>GROUP BY groups rows that have the same values in specified columns. It&#8217;s often used with aggregate functions like SUM, AVG, and COUNT.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> SQL query-related interview questions for freshers include basic syntax, simple queries, filtering, sorting, and joins.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-25-sql-dba-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 25+ SQL DBA Interview Questions and Answers<\/a><\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Interview_Queries_for_Experienced\"><\/span>SQL Interview Queries for Experienced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let&#8217;s go through some important SQL query interview questions for experienced professionals and their answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_optimize_a_slow-running_query\"><\/span>How do you optimize a slow-running query?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I usually start by checking indexes on columns used in joins or filters. I also look at the execution plan to identify full table scans or bottlenecks. Rewriting subqueries, reducing joins, and limiting returned columns often helps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_correlated_subquery\"><\/span>What is a correlated subquery?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A correlated subquery depends on the outer query. It runs once for each row processed by the outer query.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name FROM employees e WHERE salary &gt; (SELECT AVG(salary) FROM employees WHERE department = e.department);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_indexes_impact_query_performance\"><\/span>How do indexes impact query performance?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Indexes speed up searches by letting the database locate data faster, especially on large tables. However, they can slow down insert\/update operations since indexes need to be updated too.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_window_functions_and_where_are_they_used\"><\/span>What are window functions and where are they used?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Window functions perform calculations across rows without grouping. They&#8217;re used for ranking, totals, and comparisons.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name, department, salary,\n       RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>name<\/th><th>department<\/th><th>salary<\/th><th>dept_rank<\/th><\/tr><\/thead><tbody><tr><td>Carol<\/td><td>IT<\/td><td>65000<\/td><td>1<\/td><\/tr><tr><td>Frank<\/td><td>IT<\/td><td>62000<\/td><td>2<\/td><\/tr><tr><td>Bob<\/td><td>IT<\/td><td>60000<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_debug_a_failing_SQL_query_in_production\"><\/span>How do you debug a failing SQL query in production?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I break down the query and run parts of it to isolate the issue. I also check for missing joins, invalid column names, or bad data. Reviewing logs and query plans helps too.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> SQL query-related interview questions for experienced candidates often include complex joins, subqueries, indexing, and real-world scenarios.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Queries_Interview_Questions_for_2_Years_Experienced\"><\/span>SQL Queries Interview Questions for 2 Years Experienced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some SQL queries asked in interview questions for candidates with 2 years of experience.<\/p>\n\n\n\n<ul>\n<li>How would you find duplicate records in a table?<\/li>\n\n\n\n<li>How can you find the second highest salary from a table?<\/li>\n\n\n\n<li>How do you get the top 3 employees by department based on salary?<\/li>\n\n\n\n<li>Write a query to count the number of employees in each department.<\/li>\n\n\n\n<li>Write a query to fetch employees hired in the last 6 months.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Queries_Interview_Questions_for_3_Years_Experienced\"><\/span>SQL Queries Interview Questions for 3 Years Experienced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>SQL queries asked in interview for professionals with three years of experience.<\/p>\n\n\n\n<ul>\n<li>How would you write a query to check for gaps in sequential IDs?<\/li>\n\n\n\n<li>What is the difference between INNER JOIN and LEFT JOIN?<\/li>\n\n\n\n<li>When would you use a FULL OUTER JOIN?<\/li>\n\n\n\n<li>Write a query to find employees who do not have a manager assigned.<\/li>\n\n\n\n<li>Write a query to calculate the total salary expense per department.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Query_Interview_Questions_for_5_Years_Experienced\"><\/span>SQL Query Interview Questions for 5 Years Experienced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>These are some common SQL interview queries for 5 years experienced candidates.<\/p>\n\n\n\n<ul>\n<li>How do you join more than two tables?<\/li>\n\n\n\n<li>What is normalization in SQL?<\/li>\n\n\n\n<li>What is the difference between OLTP and OLAP?<\/li>\n\n\n\n<li>Write a query to identify the highest earning employee per department.<\/li>\n\n\n\n<li>How do you create and use a view in SQL?<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Query_Interview_Questions_for_7_Years_Experienced\"><\/span>SQL Query Interview Questions for 7 Years Experienced<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some frequently asked queries in SQL in interviews for professionals with 7 years of experience.<\/p>\n\n\n\n<ul>\n<li>What is a foreign key constraint?<\/li>\n\n\n\n<li>Write a query to reverse a string using SQL.<\/li>\n\n\n\n<li>Write a query to pivot table data without using PIVOT.<\/li>\n\n\n\n<li>Explain indexing strategies for improving query performance.<\/li>\n\n\n\n<li>Write a recursive query to fetch an organizational hierarchy.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-30-pl-sql-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 30+ PL\/SQL Interview Questions and Answers<\/a><\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Company-Specific_SQL_Query_Interview_Questions\"><\/span>Company-Specific SQL Query Interview Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is a list of top SQL queries asked in interviews at various IT companies in India.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Oracle_SQL_Query_Questions\"><\/span>Oracle SQL Query Questions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>These are some queries asked in SQL in oracle interview.<\/p>\n\n\n\n<ul>\n<li>How do you use the ROWNUM pseudocolumn in Oracle SQL?<\/li>\n\n\n\n<li>What is the difference between RANK() and DENSE_RANK() in Oracle SQL?<\/li>\n\n\n\n<li>How do you write a hierarchical query using CONNECT BY?<\/li>\n\n\n\n<li>How do you use MERGE statements for UPSERT operations in Oracle SQL?<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><strong>Note:<\/strong> Interview questions on Oracle SQL queries often include PL\/SQL blocks, functions, joins, and performance tuning.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-25-oracle-sql-interview-questions-with-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 25+ Oracle SQL Interview Questions With Answers<\/a><\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Queries_for_Amazon_Interview\"><\/span>SQL Queries for Amazon Interview<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here are some common SQL queries asked in interview questions at Amazon.<\/p>\n\n\n\n<ul>\n<li>Write a query to get the most viewed product in each category.<\/li>\n\n\n\n<li>Write a query to find users who bought the same item more than once.<\/li>\n\n\n\n<li>How do you write a query to find products with increasing daily sales for 3 days in a row?<\/li>\n\n\n\n<li>Write a query to calculate conversion rate per user session.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"TCS_Interview_Questions_on_SQL_Queries\"><\/span>TCS Interview Questions on SQL Queries<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>At TCS, you might come across SQL query-based interview questions.<\/p>\n\n\n\n<ul>\n<li>How do you write a query to remove duplicate rows using ROW_NUMBER()?<\/li>\n\n\n\n<li>How do you find employees who never received a bonus?<\/li>\n\n\n\n<li>How do you write a query to fetch alternate rows from a table?<\/li>\n\n\n\n<li>Write a query to get the highest and lowest salary in each department.<\/li>\n\n\n\n<li>Write a query to count how many employees joined each month.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Teradata_SQL_Queries_Interview_Questions\"><\/span>Teradata SQL Queries Interview Questions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>These are some SQL queries asked in interview questions at Teradata.<\/p>\n\n\n\n<ul>\n<li>What is QUALIFY in Teradata SQL and how is it used?<\/li>\n\n\n\n<li>Write a query using RANK in Teradata to get top 3 salaries per department.<\/li>\n\n\n\n<li>How do you use CASE in SELECT clause in Teradata?<\/li>\n\n\n\n<li>How do you handle large datasets efficiently using Teradata SQL?<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SQL_Query_MCQs\"><\/span>SQL Query MCQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are 10 SQL questions for practice. These SQL questions and answers for practice will boost your confidence before interviews.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Which_SQL_statement_is_used_to_fetch_data_from_a_database\"><\/span>1. Which SQL statement is used to fetch data from a database?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) GET<\/li>\n\n\n\n<li>b) SELECT<\/li>\n\n\n\n<li>c) FETCH<\/li>\n\n\n\n<li>d) EXTRACT<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) SELECT<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Which_of_the_following_clauses_is_used_with_aggregate_functions\"><\/span>2. Which of the following clauses is used with aggregate functions?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) WHERE<\/li>\n\n\n\n<li>b) HAVING<\/li>\n\n\n\n<li>c) ORDER BY<\/li>\n\n\n\n<li>d) DISTINCT<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) HAVING<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_What_does_the_DISTINCT_keyword_do_in_SQL\"><\/span>3. What does the DISTINCT keyword do in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) Sorts records<\/li>\n\n\n\n<li>b) Returns only unique values<\/li>\n\n\n\n<li>c) Deletes duplicate rows permanently<\/li>\n\n\n\n<li>d) Groups rows by key<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) Returns only unique values<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Which_SQL_command_removes_all_rows_but_keeps_the_table_structure\"><\/span>4. Which SQL command removes all rows but keeps the table structure?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) DELETE<\/li>\n\n\n\n<li>b) DROP<\/li>\n\n\n\n<li>c) TRUNCATE<\/li>\n\n\n\n<li>d) REMOVE<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: c) TRUNCATE<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_What_is_the_default_sorting_order_in_SQL_when_using_ORDER_BY\"><\/span>5. What is the default sorting order in SQL when using ORDER BY?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) Descending<\/li>\n\n\n\n<li>b) Ascending<\/li>\n\n\n\n<li>c) Random<\/li>\n\n\n\n<li>d) None<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) Ascending<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Which_JOIN_returns_only_matching_rows_between_two_tables\"><\/span>6. Which JOIN returns only matching rows between two tables?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) LEFT JOIN<\/li>\n\n\n\n<li>b) RIGHT JOIN<\/li>\n\n\n\n<li>c) INNER JOIN<\/li>\n\n\n\n<li>d) FULL JOIN<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: c) INNER JOIN<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Which_SQL_keyword_is_used_to_combine_the_result_of_two_SELECT_statements_while_removing_duplicates\"><\/span>7. Which SQL keyword is used to combine the result of two SELECT statements while removing duplicates?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) UNION<\/li>\n\n\n\n<li>b) UNION ALL<\/li>\n\n\n\n<li>c) INTERSECT<\/li>\n\n\n\n<li>d) MERGE<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: a) UNION<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Which_of_the_following_is_a_valid_aggregate_function_in_SQL\"><\/span>8. Which of the following is a valid aggregate function in SQL?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) SUM()<\/li>\n\n\n\n<li>b) LENGTH()<\/li>\n\n\n\n<li>c) ROUND()<\/li>\n\n\n\n<li>d) SUBSTR()<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: a) SUM()<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_Which_constraint_ensures_that_a_column_cannot_have_NULL_values\"><\/span>9. Which constraint ensures that a column cannot have NULL values?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) UNIQUE<\/li>\n\n\n\n<li>b) NOT NULL<\/li>\n\n\n\n<li>c) PRIMARY KEY<\/li>\n\n\n\n<li>d) FOREIGN KEY<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) NOT NULL<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10_What_does_the_COUNT_function_return\"><\/span>10. What does the COUNT(*) function return?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li>a) Number of columns<\/li>\n\n\n\n<li>b) Number of rows including NULLs<\/li>\n\n\n\n<li>c) Number of rows excluding NULLs<\/li>\n\n\n\n<li>d) Sum of numeric column values<\/li>\n<\/ul>\n\n\n\n<p><strong>Answer: b) Number of rows including NULLs<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Prepare_for_SQL_Query_Interview_Questions\"><\/span>How to Prepare for SQL Query Interview Questions?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-1024x682.webp\" alt=\"SQL Query Interview\" class=\"wp-image-9697\" srcset=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-1024x682.webp 1024w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-300x200.webp 300w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-768x512.webp 768w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-1170x780.webp 1170w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-585x390.webp 585w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview-263x175.webp 263w, https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2026\/04\/sql-query-interview.webp 1220w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Here are some practical tips to help you prepare for SQL query interview questions:<\/p>\n\n\n\n<ul>\n<li>Go through SQL query questions and answers for practice to build strong fundamentals.<\/li>\n\n\n\n<li>Solve practical SQL coding questions daily for hands-on skills.<\/li>\n\n\n\n<li>Revise SQL query examples with answers to learn common patterns.<\/li>\n\n\n\n<li>Focus on top SQL queries interview questions often asked in hiring rounds.<\/li>\n\n\n\n<li>Practice real SQL queries in interviews like joins, grouping, and indexing.<\/li>\n\n\n\n<li>Review key SQL theory questions to strengthen concepts.<\/li>\n\n\n\n<li>Use sample databases and break queries step by step for clarity.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-verse\"><strong>Also Read - <a href=\"https:\/\/www.hirist.tech\/blog\/top-50-mysql-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 50+ MySQL Interview Questions and Answers<\/a><\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wrapping_Up\"><\/span>Wrapping Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>And this wraps up the 100 most commonly asked SQL query interview questions and answers. Practice these regularly, understand the logic, and you&#8217;ll feel more confident during interviews.<\/p>\n\n\n\n<p>Looking for SQL jobs? Visit Hirist \u2013 an online job portal built for tech professionals. You can easily find the top SQL jobs in India, all in one place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777283812935\"><strong class=\"schema-faq-question\">What are some important queries in SQL for interview?<\/strong> <p class=\"schema-faq-answer\">Some imp SQL query for interviews include \u2013<br\/>Find second highest salary using subquery<br\/>Count orders per customer<br\/>Use JOIN to combine two tables<br\/>Get top N records per group<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284114277\"><strong class=\"schema-faq-question\">How to explain SQL query in interview?<\/strong> <p class=\"schema-faq-answer\">Break it down step-by-step \u2013 mention what the query does, which tables it uses, how joins or filters work, and what the final output looks like.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284121151\"><strong class=\"schema-faq-question\">What are some commonly asked SQL command interview questions?<\/strong> <p class=\"schema-faq-answer\">Common SQL command interview questions include \u2013<br\/>What does SELECT do?<br\/>Difference between DELETE and TRUNCATE<br\/>How does UPDATE work with a JOIN?<br\/>What is a WHERE clause?<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284136490\"><strong class=\"schema-faq-question\">How to write SQL query easily?<\/strong> <p class=\"schema-faq-answer\">Understand the schema, then write from SELECT to FROM, apply joins or conditions, and use aliases for clarity.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284144064\"><strong class=\"schema-faq-question\">What are some frequently asked performance tuning in SQL server interview questions?<\/strong> <p class=\"schema-faq-answer\">Topics include indexing, query plans, avoiding full table scans, and using EXISTS vs IN. These are common SQL queries questions for interview rounds.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284152069\"><strong class=\"schema-faq-question\">Give me a list of MySQL query interview questions.<\/strong> <p class=\"schema-faq-answer\">Sample SQL query questions include \u2013<br\/>Use of LIMIT and OFFSET<br\/>String functions like CONCAT()<br\/>Filtering with BETWEEN and LIKE<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284168069\"><strong class=\"schema-faq-question\">How to practice SQL queries for interview?<\/strong> <p class=\"schema-faq-answer\">Practice SQL query-based interview questions using sample databases like Sakila or Employees on platforms such as SQLFiddle, Mode Analytics, or your local SQL editor.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284178568\"><strong class=\"schema-faq-question\">What are the common SQL queries for software testers?<\/strong> <p class=\"schema-faq-answer\">Here are some frequently asked interview questions for SQL queries for testers that help in validating data and ensuring accuracy. These are also the most practical SQL queries for testing interview rounds.<br\/>Write a query to compare record counts between source and target tables.<br\/>Write a query to check for NULL values in mandatory fields.<br\/>Write a query to validate data mappings between two related tables using JOIN.<br\/>Write a query to find duplicate records based on key columns.<br\/>Write a query to compare row-level data between staging and final tables.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284190027\"><strong class=\"schema-faq-question\">What are the frequently asked SQL questions for data engineer?<\/strong> <p class=\"schema-faq-answer\">For data engineers, interviews often focus on data quality, pipelines, and integrity checks. Common questions include:<br\/>Write a query to compare row counts between staging and final tables.<br\/>Write a query to validate referential integrity between parent and child tables.<br\/>Write a query to detect slowly changing dimension (SCD) changes.<br\/>Write a query to check for duplicates before loading data.<br\/>Write a query to validate incremental data loads.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284198976\"><strong class=\"schema-faq-question\">What are the common SQL query interview questions for data analyst?<\/strong> <p class=\"schema-faq-answer\">For data analysts, questions usually test reporting and trend analysis skills. Common queries include:<br\/>Write a query to calculate the median of a numeric column.<br\/>Write a query to calculate monthly user retention.<br\/>Write a query to identify user churn over time.<br\/>Write a query to calculate percentage contribution of each category to total sales.<br\/>Write a query to rank products or customers based on sales.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284210650\"><strong class=\"schema-faq-question\">What are the common ETL testing SQL queries interview questions?<\/strong> <p class=\"schema-faq-answer\">Here are some of the most asked interview questions on JOIN in SQL that test your ability to work with related tables. These are also popular interview questions on SQL JOIN queries across different experience levels.<br\/>Write a query using INNER JOIN to fetch customers who placed orders.<br\/>Write a query using LEFT JOIN to list all customers, including those without orders.<br\/>Write a query using RIGHT JOIN to show all orders with or without matching customers.<br\/>Write a query using FULL OUTER JOIN to combine customer and order data.<br\/>Write a query using SELF JOIN to display employees along with their managers.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284228409\"><strong class=\"schema-faq-question\">What are the most asked DB queries for interview?<\/strong> <p class=\"schema-faq-answer\">Here are some of the most important DB queries interview questions that commonly appear in interviews:<br\/>Write a query to list all tables in a database.<br\/>Write a query to fetch column names and data types for a given table.<br\/>Write a query to list indexes created on a table.<br\/>Write a query to display the current database name and user.<br\/>Write a query to count the total number of rows in each table of a database.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284237685\"><strong class=\"schema-faq-question\">Are DBMS queries interview questions tough?<\/strong> <p class=\"schema-faq-answer\">DBMS queries interview questions are not necessarily tough, but they can be tricky if you lack clarity on concepts. Most questions focus on basics like transactions, ACID properties, normalization, and views.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284242422\"><strong class=\"schema-faq-question\">Where can I find SQL practical interview questions?<\/strong> <p class=\"schema-faq-answer\">You can find plenty of commonly asked questions and answers in this blog itself. It covers SQL practical questions for interview such as joins, subqueries, aggregations, indexing, and problem-solving. These examples will help you practice effectively and prepare with confidence.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284251405\"><strong class=\"schema-faq-question\">How to solve SQL programming interview questions?<\/strong> <p class=\"schema-faq-answer\">Break queries step by step. First, identify the tables and columns needed, then apply filters, joins, or aggregations, and finally refine using clauses like GROUP BY or ORDER BY. Practicing real queries will help you approach problems logically.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284263034\"><strong class=\"schema-faq-question\">Are SQL coding interview questions difficult?<\/strong> <p class=\"schema-faq-answer\">SQL coding interview questions are not difficult if you practice regularly. They usually test joins, subqueries, ranking, and aggregations. With hands-on practice on real datasets, you can solve them with confidence.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284270596\"><strong class=\"schema-faq-question\">What are some tips to prepare for SQL query interview questions?<\/strong> <p class=\"schema-faq-answer\">Focus on real-life use cases, revise JOINs, use online platforms, and solve daily scenarios with different query types.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777284277699\"><strong class=\"schema-faq-question\">What is the average salary for SQL-skilled professionals in India?<\/strong> <p class=\"schema-faq-answer\">According to AmbitionBox, as of 2025, SQL Developer salaries in India typically range from \u20b92.0 Lakhs to \u20b99.0 Lakhs per year. Specialized roles and positions in top companies may offer higher compensation.<\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL queries are commands used to talk to a database. They first appeared in the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6695,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,19],"tags":[32,34,33,83],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog<\/title>\n<meta name=\"description\" content=\"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.\" \/>\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.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog\" \/>\n<meta property=\"og:description\" content=\"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/\" \/>\n<meta property=\"og:site_name\" content=\"Hirist Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hirist.jobs\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-02T12:19:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-28T03:00:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1143\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"hiristBlog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hiristBlog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"24 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/\",\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/\",\"name\":\"Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.hirist.tech\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg\",\"datePublished\":\"2025-05-02T12:19:12+00:00\",\"dateModified\":\"2026-04-28T03:00:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/f40a5a435d73195ec4e424a307b0c26b\"},\"description\":\"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596\"},{\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage\",\"url\":\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg\",\"contentUrl\":\"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg\",\"width\":2000,\"height\":1143,\"caption\":\"sql query interview questions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.hirist.tech\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Top 100+ SQL Query Interview Questions and Answers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/#website\",\"url\":\"https:\/\/www.hirist.tech\/blog\/\",\"name\":\"Hirist Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.hirist.tech\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/f40a5a435d73195ec4e424a307b0c26b\",\"name\":\"hiristBlog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1d0fb418cc48cd31b61160060c199240?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1d0fb418cc48cd31b61160060c199240?s=96&d=mm&r=g\",\"caption\":\"hiristBlog\"},\"sameAs\":[\"https:\/\/www.hirist.tech\/blog\"],\"url\":\"https:\/\/www.hirist.tech\/blog\/author\/hiristblog\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935\",\"position\":1,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935\",\"name\":\"What are some important queries in SQL for interview?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Some imp SQL query for interviews include \u2013<br\/>Find second highest salary using subquery<br\/>Count orders per customer<br\/>Use JOIN to combine two tables<br\/>Get top N records per group\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277\",\"position\":2,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277\",\"name\":\"How to explain SQL query in interview?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Break it down step-by-step \u2013 mention what the query does, which tables it uses, how joins or filters work, and what the final output looks like.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151\",\"position\":3,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151\",\"name\":\"What are some commonly asked SQL command interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Common SQL command interview questions include \u2013<br\/>What does SELECT do?<br\/>Difference between DELETE and TRUNCATE<br\/>How does UPDATE work with a JOIN?<br\/>What is a WHERE clause?\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490\",\"position\":4,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490\",\"name\":\"How to write SQL query easily?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Understand the schema, then write from SELECT to FROM, apply joins or conditions, and use aliases for clarity.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064\",\"position\":5,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064\",\"name\":\"What are some frequently asked performance tuning in SQL server interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Topics include indexing, query plans, avoiding full table scans, and using EXISTS vs IN. These are common SQL queries questions for interview rounds.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069\",\"position\":6,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069\",\"name\":\"Give me a list of MySQL query interview questions.\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Sample SQL query questions include \u2013<br\/>Use of LIMIT and OFFSET<br\/>String functions like CONCAT()<br\/>Filtering with BETWEEN and LIKE\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069\",\"position\":7,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069\",\"name\":\"How to practice SQL queries for interview?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Practice SQL query-based interview questions using sample databases like Sakila or Employees on platforms such as SQLFiddle, Mode Analytics, or your local SQL editor.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568\",\"position\":8,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568\",\"name\":\"What are the common SQL queries for software testers?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Here are some frequently asked interview questions for SQL queries for testers that help in validating data and ensuring accuracy. These are also the most practical SQL queries for testing interview rounds.<br\/>Write a query to compare record counts between source and target tables.<br\/>Write a query to check for NULL values in mandatory fields.<br\/>Write a query to validate data mappings between two related tables using JOIN.<br\/>Write a query to find duplicate records based on key columns.<br\/>Write a query to compare row-level data between staging and final tables.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027\",\"position\":9,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027\",\"name\":\"What are the frequently asked SQL questions for data engineer?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"For data engineers, interviews often focus on data quality, pipelines, and integrity checks. Common questions include:<br\/>Write a query to compare row counts between staging and final tables.<br\/>Write a query to validate referential integrity between parent and child tables.<br\/>Write a query to detect slowly changing dimension (SCD) changes.<br\/>Write a query to check for duplicates before loading data.<br\/>Write a query to validate incremental data loads.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976\",\"position\":10,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976\",\"name\":\"What are the common SQL query interview questions for data analyst?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"For data analysts, questions usually test reporting and trend analysis skills. Common queries include:<br\/>Write a query to calculate the median of a numeric column.<br\/>Write a query to calculate monthly user retention.<br\/>Write a query to identify user churn over time.<br\/>Write a query to calculate percentage contribution of each category to total sales.<br\/>Write a query to rank products or customers based on sales.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650\",\"position\":11,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650\",\"name\":\"What are the common ETL testing SQL queries interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Here are some of the most asked interview questions on JOIN in SQL that test your ability to work with related tables. These are also popular interview questions on SQL JOIN queries across different experience levels.<br\/>Write a query using INNER JOIN to fetch customers who placed orders.<br\/>Write a query using LEFT JOIN to list all customers, including those without orders.<br\/>Write a query using RIGHT JOIN to show all orders with or without matching customers.<br\/>Write a query using FULL OUTER JOIN to combine customer and order data.<br\/>Write a query using SELF JOIN to display employees along with their managers.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409\",\"position\":12,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409\",\"name\":\"What are the most asked DB queries for interview?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Here are some of the most important DB queries interview questions that commonly appear in interviews:<br\/>Write a query to list all tables in a database.<br\/>Write a query to fetch column names and data types for a given table.<br\/>Write a query to list indexes created on a table.<br\/>Write a query to display the current database name and user.<br\/>Write a query to count the total number of rows in each table of a database.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685\",\"position\":13,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685\",\"name\":\"Are DBMS queries interview questions tough?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"DBMS queries interview questions are not necessarily tough, but they can be tricky if you lack clarity on concepts. Most questions focus on basics like transactions, ACID properties, normalization, and views.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422\",\"position\":14,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422\",\"name\":\"Where can I find SQL practical interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"You can find plenty of commonly asked questions and answers in this blog itself. It covers SQL practical questions for interview such as joins, subqueries, aggregations, indexing, and problem-solving. These examples will help you practice effectively and prepare with confidence.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405\",\"position\":15,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405\",\"name\":\"How to solve SQL programming interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Break queries step by step. First, identify the tables and columns needed, then apply filters, joins, or aggregations, and finally refine using clauses like GROUP BY or ORDER BY. Practicing real queries will help you approach problems logically.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034\",\"position\":16,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034\",\"name\":\"Are SQL coding interview questions difficult?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"SQL coding interview questions are not difficult if you practice regularly. They usually test joins, subqueries, ranking, and aggregations. With hands-on practice on real datasets, you can solve them with confidence.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596\",\"position\":17,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596\",\"name\":\"What are some tips to prepare for SQL query interview questions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Focus on real-life use cases, revise JOINs, use online platforms, and solve daily scenarios with different query types.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699\",\"position\":18,\"url\":\"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699\",\"name\":\"What is the average salary for SQL-skilled professionals in India?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"According to AmbitionBox, as of 2025, SQL Developer salaries in India typically range from \u20b92.0 Lakhs to \u20b99.0 Lakhs per year. Specialized roles and positions in top companies may offer higher compensation.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog","description":"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.","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.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/","og_locale":"en_US","og_type":"article","og_title":"Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog","og_description":"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.","og_url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/","og_site_name":"Hirist Blog","article_publisher":"https:\/\/www.facebook.com\/hirist.jobs","article_published_time":"2025-05-02T12:19:12+00:00","article_modified_time":"2026-04-28T03:00:15+00:00","og_image":[{"width":2000,"height":1143,"url":"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg","type":"image\/jpeg"}],"author":"hiristBlog","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hiristBlog","Est. reading time":"24 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/","url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/","name":"Top 100+ SQL Query Interview Questions and Answers (2026) - Hirist Blog","isPartOf":{"@id":"https:\/\/www.hirist.tech\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage"},"image":{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg","datePublished":"2025-05-02T12:19:12+00:00","dateModified":"2026-04-28T03:00:15+00:00","author":{"@id":"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/f40a5a435d73195ec4e424a307b0c26b"},"description":"Prepare for interview with these top 100 SQL query interview questions and answers for experienced and freshers with examples of SQL commands.","breadcrumb":{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596"},{"@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#primaryimage","url":"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg","contentUrl":"https:\/\/www.hirist.tech\/blog\/wp-content\/uploads\/2025\/05\/sql-query-interview-questions.jpg","width":2000,"height":1143,"caption":"sql query interview questions"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hirist.tech\/blog\/"},{"@type":"ListItem","position":2,"name":"Top 100+ SQL Query Interview Questions and Answers"}]},{"@type":"WebSite","@id":"https:\/\/www.hirist.tech\/blog\/#website","url":"https:\/\/www.hirist.tech\/blog\/","name":"Hirist Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hirist.tech\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/f40a5a435d73195ec4e424a307b0c26b","name":"hiristBlog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hirist.tech\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1d0fb418cc48cd31b61160060c199240?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1d0fb418cc48cd31b61160060c199240?s=96&d=mm&r=g","caption":"hiristBlog"},"sameAs":["https:\/\/www.hirist.tech\/blog"],"url":"https:\/\/www.hirist.tech\/blog\/author\/hiristblog\/"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935","position":1,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777283812935","name":"What are some important queries in SQL for interview?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Some imp SQL query for interviews include \u2013<br\/>Find second highest salary using subquery<br\/>Count orders per customer<br\/>Use JOIN to combine two tables<br\/>Get top N records per group","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277","position":2,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284114277","name":"How to explain SQL query in interview?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Break it down step-by-step \u2013 mention what the query does, which tables it uses, how joins or filters work, and what the final output looks like.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151","position":3,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284121151","name":"What are some commonly asked SQL command interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Common SQL command interview questions include \u2013<br\/>What does SELECT do?<br\/>Difference between DELETE and TRUNCATE<br\/>How does UPDATE work with a JOIN?<br\/>What is a WHERE clause?","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490","position":4,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284136490","name":"How to write SQL query easily?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Understand the schema, then write from SELECT to FROM, apply joins or conditions, and use aliases for clarity.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064","position":5,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284144064","name":"What are some frequently asked performance tuning in SQL server interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Topics include indexing, query plans, avoiding full table scans, and using EXISTS vs IN. These are common SQL queries questions for interview rounds.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069","position":6,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284152069","name":"Give me a list of MySQL query interview questions.","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Sample SQL query questions include \u2013<br\/>Use of LIMIT and OFFSET<br\/>String functions like CONCAT()<br\/>Filtering with BETWEEN and LIKE","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069","position":7,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284168069","name":"How to practice SQL queries for interview?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Practice SQL query-based interview questions using sample databases like Sakila or Employees on platforms such as SQLFiddle, Mode Analytics, or your local SQL editor.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568","position":8,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284178568","name":"What are the common SQL queries for software testers?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Here are some frequently asked interview questions for SQL queries for testers that help in validating data and ensuring accuracy. These are also the most practical SQL queries for testing interview rounds.<br\/>Write a query to compare record counts between source and target tables.<br\/>Write a query to check for NULL values in mandatory fields.<br\/>Write a query to validate data mappings between two related tables using JOIN.<br\/>Write a query to find duplicate records based on key columns.<br\/>Write a query to compare row-level data between staging and final tables.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027","position":9,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284190027","name":"What are the frequently asked SQL questions for data engineer?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"For data engineers, interviews often focus on data quality, pipelines, and integrity checks. Common questions include:<br\/>Write a query to compare row counts between staging and final tables.<br\/>Write a query to validate referential integrity between parent and child tables.<br\/>Write a query to detect slowly changing dimension (SCD) changes.<br\/>Write a query to check for duplicates before loading data.<br\/>Write a query to validate incremental data loads.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976","position":10,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284198976","name":"What are the common SQL query interview questions for data analyst?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"For data analysts, questions usually test reporting and trend analysis skills. Common queries include:<br\/>Write a query to calculate the median of a numeric column.<br\/>Write a query to calculate monthly user retention.<br\/>Write a query to identify user churn over time.<br\/>Write a query to calculate percentage contribution of each category to total sales.<br\/>Write a query to rank products or customers based on sales.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650","position":11,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284210650","name":"What are the common ETL testing SQL queries interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Here are some of the most asked interview questions on JOIN in SQL that test your ability to work with related tables. These are also popular interview questions on SQL JOIN queries across different experience levels.<br\/>Write a query using INNER JOIN to fetch customers who placed orders.<br\/>Write a query using LEFT JOIN to list all customers, including those without orders.<br\/>Write a query using RIGHT JOIN to show all orders with or without matching customers.<br\/>Write a query using FULL OUTER JOIN to combine customer and order data.<br\/>Write a query using SELF JOIN to display employees along with their managers.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409","position":12,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284228409","name":"What are the most asked DB queries for interview?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Here are some of the most important DB queries interview questions that commonly appear in interviews:<br\/>Write a query to list all tables in a database.<br\/>Write a query to fetch column names and data types for a given table.<br\/>Write a query to list indexes created on a table.<br\/>Write a query to display the current database name and user.<br\/>Write a query to count the total number of rows in each table of a database.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685","position":13,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284237685","name":"Are DBMS queries interview questions tough?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"DBMS queries interview questions are not necessarily tough, but they can be tricky if you lack clarity on concepts. Most questions focus on basics like transactions, ACID properties, normalization, and views.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422","position":14,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284242422","name":"Where can I find SQL practical interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can find plenty of commonly asked questions and answers in this blog itself. It covers SQL practical questions for interview such as joins, subqueries, aggregations, indexing, and problem-solving. These examples will help you practice effectively and prepare with confidence.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405","position":15,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284251405","name":"How to solve SQL programming interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Break queries step by step. First, identify the tables and columns needed, then apply filters, joins, or aggregations, and finally refine using clauses like GROUP BY or ORDER BY. Practicing real queries will help you approach problems logically.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034","position":16,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284263034","name":"Are SQL coding interview questions difficult?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"SQL coding interview questions are not difficult if you practice regularly. They usually test joins, subqueries, ranking, and aggregations. With hands-on practice on real datasets, you can solve them with confidence.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596","position":17,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284270596","name":"What are some tips to prepare for SQL query interview questions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Focus on real-life use cases, revise JOINs, use online platforms, and solve daily scenarios with different query types.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699","position":18,"url":"https:\/\/www.hirist.tech\/blog\/top-100-sql-query-interview-questions-and-answers\/#faq-question-1777284277699","name":"What is the average salary for SQL-skilled professionals in India?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"According to AmbitionBox, as of 2025, SQL Developer salaries in India typically range from \u20b92.0 Lakhs to \u20b99.0 Lakhs per year. Specialized roles and positions in top companies may offer higher compensation.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/posts\/6677"}],"collection":[{"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/comments?post=6677"}],"version-history":[{"count":39,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/posts\/6677\/revisions"}],"predecessor-version":[{"id":9700,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/posts\/6677\/revisions\/9700"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/media\/6695"}],"wp:attachment":[{"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/media?parent=6677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/categories?post=6677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hirist.tech\/blog\/wp-json\/wp\/v2\/tags?post=6677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}