Share E-Book

Grokking the SQL Interview. Master SQL, Excel in Interviews, Elevate Your Career (Javin Paul) (z-library.sk, 1lib.sk, z-lib.sk)

Author

Rating 3.5 AI initial rating

Log in to rate

SQL
Language English

Ready to master SQL and ace your dream job interview? Dive into "Grokking the SQL Interview," your passport to SQL expertise! Uncover the secrets to crafting powerful queries, mastering joins, and acing real-world SQL interviews? Are you on the brink of a career in data analytics, database administration, or software development? Perhaps you're gearing up for a crucial job interview that hinges on your SQL skills. If so, "Grokking the SQL Interview" is your essential companion on the path to SQL mastery and interview success. As a Java developer who has cleared SQL interviews, I can attest that SQL interviews are not easy, given the vast nature of SQL and the variety of concepts and topics it covers. When I was preparing for Java interviews, I was looking for a resource where I learn and prepare SQL questions from a programmer’s perspective rather than a DBA, but I couldn’t find any. Grokking the SQL Interview is my effort to fill that gap and become an excellent resource for anyone looking to master SQL and prepare for SQL interviews. Whenever I prepare for Java Interview, I always prepare about SQL and Linux; these are everywhere. That’s why I decided to cover essential topics from an interview perspective when I thought to write about this book. The book covers a wide range of topics, starting with the basics of SQL and database design, and progressing to more advanced topics like SQL queries, joins, indexes, group-by and aggregate functions, stored procedures, triggers and views, database normalization, transactions, window functions, and common interview questions. One of the best things about this book is that it includes many real-world SQL questions commonly asked in job interviews. This means that by studying the questions and answers in this book, you will be well-prepared for any SQL interview. Unlock the Power of SQL SQL (Structured Query Language) is the cornerstone of modern data management and analysis. It's the language that empowers you to interact

Format PDF
Size 12.5 MB
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
(This page has no text content)
Page 3
Grokking the SQL Interview © 2023, Javin Paul Version 1.0 - August 2023 All rights reserved. This book or any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of the publisher except for the use of brief quotations in a book review.
Page 4
Table of Content Overview .......................................................................................................................... 1 Why Prepare for SQL and Database for Interviews? ....................................................... 2 How to prepare SQL for Interviews? .................................................................................. 3 Which SQL and Database topics to Prepare for Interviews? .......................................... 5 CHAPTER 1: SQL and Database Telephonic Interview Questions ..... 6 1 Difference between UNION and UNION ALL in SQL ........................................... 7 2 Difference between WHERE and HAVING clause in SQL? ................................. 10 3 Describe the difference between clustered and non-clustered indexes in a database? ....................................................................................................................... 13 4 Write an SQL query to find the second highest salary of an employee without using TOP or LIMIT? .................................................................................. 15 5 How to find duplicate rows in the database? ........................................................... 16 6 Difference between correlated and non-correlated subquery in SQL? ................ 17 7 How many clustered indexes you can have in a table? .......................................... 20 8 Difference between the PRIMARY key and the UNIQUE key constraint in SQL? .......................................................................................................................... 21 9 Difference between view and materialized view in SQL? ...................................... 23 10 Difference between TRUNCATE, DELETE and DROP in SQL? ........................ 25 11 What is Referential Integrity in a relational database? .......................................... 27 12 What is Normalization? ............................................................................................. 29 13 When a table is said to be in 1NF, 2nd NF, and 3rd NF? ...................................... 33 14 Describe the difference between ISNULL() and COALESCE() in SQL Server? ....... 35 15 How do you ensure that only values between 1 to 5 are allowed in an integer column? ........................................................................................................... 36 16 Difference between CHAR and VARCHAR data types in SQL? ......................... 38 17 Difference between VARCHAR and NVARCHAR in SQL Server? .................... 40 18 How do you get Day, Month, and Year from a date in SQL Server? ................... 40 19 How to check if a date is valid in SQL? .................................................................... 41 20 Difference between LEFT OUTER JOIN and INNER JOIN in SQL? ................. 43
Page 5
21 What is SELF JOIN in SQL? ...................................................................................... 44 22 In a classical Employee and Department relationship, write SQL query to print all departments and number of employees on each department. ............... 44 23 Difference between COUNT(*), COUNT(1), and COUNT(column_ name) in SQL? .......................................................................................................................... 45 24 What is Database statistics? How it affects the performance of your Query? .... 47 25 Suppose you have to create a compound index in a table, involving two columns like book_id and active. Now you can create them as either (book_id, active) or (active, book_id), do you think the order of columns in an index matter? How it will affect your SQL queries? ..................................... 49 26 What do _ and % are used in the SQL query? ......................................................... 50 27 How do you ensure that a particular SQL query will use a particular Index? .... 51 28 In SQL Server, which one is fastest and slowest between an index seek, an index scan, and table scan? ................................................................................... 53 29 What does NULL = NULL will return in SQL? ...................................................... 54 30 Write SQL query to find all rows where EMP_NAME, a VARCHAR column is NULL? ........................................................................................................ 55 31 What is the temp table? .............................................................................................. 56 32 What is the fastest way to empty or clear a table? .................................................. 57 33 What is an identity column in SQL Server? How do you return an identity value from a table? ...................................................................................................... 59 34 How do you return an identity value from a table with a trigger? ....................... 61 35 How do you return a value from a stored procedure? ........................................... 61 36 How do you return a VARCHAR value from a stored procedure? ..................... 63 37 If you have a column that will only have values between 1 and 250 what data type will you use? ................................................................................................ 63 38 Difference between LEFT and RIGHT OUTER JOIN in SQL? ............................ 64 39 Can you write an SQL query to select all last names that start with 'T'? ............. 64 40 How would you select all rows where the date is 20231002? ................................ 65 41 What is the difference between a local and global temporary table in SQL Server? .................................................................................................................. 65 42 How do you create a copy of a table in SQL Server? .............................................. 66 43 How do you change the data type of a column in a table in SQL? ....................... 67 44 What data type should you use to store monetary values in a table? ................... 68 45 What does SELECT 3/2 will return? 1 or 1.5? ......................................................... 69 46 What is the maximum value that Decimal (6, 5) can hold in SQL Server? ......... 70 47 If you have a table with one integer column ID, and it has three values 101, 201, and NULL? What will the following SQL query SELECT * FROM TestTable where ID !=101 will return? ....................................................... 70
Page 6
48 What is your favorite SQL book? .............................................................................. 71 49 Tell me two SQL best practices you follow? ............................................................ 71 50 What is the different ISOLATION level in the Microsoft SQL Server database? ......... 72 51 If you create a local temp table and then call a proc is the temp table available inside the proc? ........................................................................................... 74 52 Which date format is the only safe one to use when passing dates as strings? ... 76 53 How do you suppress rows affected messages when executing an insert statement in SQL Server? ........................................................................................... 76 54 Difference between ANSI-89 and ANSI-92 syntax of writing SQL Join? ........... 77 55 Differences between IN and EXISTS (and NOT IN, and NOT EXISTS) in SQL? ....... 78 CHAPTER 2: SQL JOIN ......................................................................................... 81 1 What is the difference between INNER JOIN and LEFT JOIN in SQL? ............. 84 2 How do you perform a simple INNER JOIN between two tables in SQL? ......... 84 3 Explain the usage of RIGHT JOIN with an example. ............................................ 85 4 How can you perform a FULL JOIN to retrieve all rows from two tables, even when there are no matches?.............................................................................. 85 5 What is a SELF JOIN, and in what scenarios is it useful? ...................................... 85 6 How do you perform a SELF JOIN in SQL? ............................................................ 86 7 What is the result of a CROSS JOIN? ....................................................................... 86 8 How do you perform a CROSS JOIN in SQL? ........................................................ 86 9 Explain the concept of Non-Equi Join. .................................................................... 86 10 How do you handle NULL values during joins? ..................................................... 87 11 What is the difference between an INNER JOIN and an equi-join?.................... 87 12 How can you retrieve records from the left table that do not have corresponding matches in the right table? ............................................................... 87 13 What is the difference between a LEFT JOIN and a RIGHT JOIN? .................... 87 14 How do you perform a multi-table join in SQL? .................................................... 88 15 How can you find records with no matching entries in either of the two joined tables? ................................................................................................................ 88 16 When should you use an INNER JOIN over a LEFT JOIN or RIGHT JOIN? ... 89 17 How can you find records with matching values in one table but not in another? ........................................................................................................................ 89 18 What are the key differences between a FULL JOIN and a UNION? .................. 89 19 How do you combine results from multiple queries without using a join? ........ 90 20 What is the difference between a self join and a regular join? .............................. 90 21 How can you find the top N employees based on their salary using joins? ........ 90 22 How can you find employees who have the same manager using a self join? .... 91 23 What is the purpose of using table aliases in SQL joins? ....................................... 91
Page 7
24 How can you join three or more tables in a single query?..................................... 92 25 Explain how you can perform a LEFT JOIN between two tables and keep only the rows that do not match. .............................................................................. 92 26 Can you use a JOIN without specifying a join condition? If yes, what will be the result? ................................................................................................................ 92 27 What is the benefit of using an equi-join over a non-equi join? .......................... 93 28 How do you perform a LEFT JOIN between two tables and include all rows rom the left table, even if there are multiple matches in the right table? ............ 93 29 How do you perform an anti-join (retrieve records that exist in one table but not in another)? .................................................................................................... 94 30 How can you find the average salary of employees in each department using SQL joins? .......................................................................................................... 94 CHAPTER 3: SQL QUERIES ............................................................................. 95 1 Can you write an SQL query to show Employee (names) who have a bigger salary than their manager? ............................................................................. 99 2 Write an SQL query to find Employees who have the biggest salary in their Department? ................................................................................................................ 99 3 Write an SQL query to list Departments that have less than 3 people in it?..... 100 4 Write an SQL query to show all Departments along with the number of people there? .............................................................................................................. 101 5 Can you write an SQL query to show all Employees that don't have a manager in the same department? .......................................................................... 101 6 Can you write SQL query to list all Departments along with the total salary there? ................................................................................................................ 102 7 How do you find the second highest salary in the employee table? ................... 102 8 How do you find the duplicate rows in a table? .................................................... 103 9 How do you copy all rows of a table using SQL query?(solution) ..................... 103 10 How do you remove the duplicate rows from the table? ..................................... 103 11 How to find 2nd highest salary without using a co-related subquery? ............. 104 12 There exists an Order table and a Customer table, find all Customers who have never ordered .......................................................................................... 104 CHAPTER 4: Indexes ......................................................................................... 105 1 What is index in database? ....................................................................................... 106 2 What are different types of index in Oracle or SQL Server? ............................... 106 3 How does index work? ............................................................................................. 107 4 What is index scan? ................................................................................................... 107 5 What is index seek? ................................................................................................... 107
Page 8
6 What is difference between index scan and index seek in database? ................. 108 7 What is difference between table scan and index scan? ....................................... 109 8 What is difference between Clustered and Non-Clustered index in a table? ... 109 9 I have a table which has clustered index on column 1, can I create another clustered index on column 2? .................................................................................. 110 10 What is composite index in SQL? ........................................................................... 111 11 Does the order of columns matter in a composite index? ................................... 111 12 What is the disadvantage of having many indices in a table? ............................. 112 CHAPTER 5: GROUP BY .................................................................................... 113 CHAPTER 6: SQL Date and Time Interview Questions ........... 122 1 How do you find all records modified between two dates in SQL? ................... 124 2 How do you extract the year from a date in SQL? ................................................ 125 3 How can you add 3 months to a given date in SQL? ............................................ 125 4 How do you find the number of days between two dates in SQL? ..................... 125 5 Explain the difference between DATE and DATETIME data types. ................. 125 6. How do you convert a date to a different date format in SQL? .......................... 126 7 How can you find records that fall within a specific month and year? ............. 126 8 How do you handle time zone conversions in SQL? ............................................ 126 9 Can you enforce a constraint to ensure a date column always contains future dates? ............................................................................................................... 127 10 How can you find the first and last day of the current month? .......................... 127 11 How do you find records with overlapping date ranges in SQL? ....................... 127 12 How can you calculate the age of a person from their birthdate? ...................... 128 13 Explain the significance of the UNIX timestamp and how to convert it to a readable date format. ............................................................................................. 128 14 How do you get the current date and time in SQL? ............................................. 128 15 How can you convert a string to a date in SQL? ................................................... 129 16 How do you find the day of the week for a given date in SQL? .......................... 129 17 How do you find the number of weekdays (excluding weekends) between two dates? ................................................................................................................... 130 18 How do you extract the time part from a DATETIME column in SQL? .......... 130 19 How can you find the records with the latest date in a table? ............................. 130 20 Explain the concept of leap years and how you would identify if a year is a leap year in SQL. ..................................................................................................... 131 CHAPTER 7: Aggregate Functions ......................................................... 132 1 What are aggregate functions in SQL, and what is their purpose? .................... 135 2 List some common aggregate functions in SQL. .................................................. 135
Page 9
3 How do you use the COUNT function to count the number of rows in a table? ....... 135 4 What is the difference between the COUNT function with DISTINCT and without DISTINCT? .......................................................................................... 135 5 How can you use the SUM function to calculate the total value of a specific column? ...................................................................................................................... 136 6 How do you calculate the average (mean) of a column using the AVG function? ..... 136 7 Explain the usage of the GROUP BY clause with aggregate functions. ............. 136 8 How does the HAVING clause differ from the WHERE clause when using aggregate functions? ....................................................................................... 136 9 What is the purpose of the ROLLUP operator in aggregate functions? ............ 136 10 Can you use multiple aggregate functions in a single SQL query? ..................... 137 11 How do you handle NULL values when using aggregate functions? ................. 137 12 What is string aggregation, and how can you achieve it in SQL? ....................... 137 13 How do aggregate functions interact with different types of joins? ................... 137 14 Can you use aggregate functions with window functions? ................................. 137 15 How do you optimize the performance of queries using aggregate functions on large datasets? ..................................................................................... 138 16 What is the purpose of the GROUPING SETS clause in aggregate functions? ........... 138 17 How do you apply aggregate functions in real-world scenarios like sales analysis or financial reporting? ...................................................................... 138 18 How are aggregate functions used in data visualization and reporting tools? ............. 138 19 Can you create custom aggregate functions in SQL? ........................................... 138 20 Explain how you use aggregate functions with NoSQL databases. .................... 139 CHAPTER 8: Stored Procedure ................................................................. 140 1 What is a stored procedure? .................................................................................... 143 2 What are the advantages of using stored procedures? ......................................... 143 3 How do you create a stored procedure in SQL? ................................................... 144 4 How do you call a stored procedure from SQL or an application? .................... 144 5 What are input and output parameters in stored procedures? ........................... 144 6 How do you handle errors in a stored procedure? ............................................... 144 7 Can a stored procedure call another stored procedure? ...................................... 144 8 What are the different types of parameters that a stored procedure can have? ........... 145 9 How do you pass multiple values to a stored procedure as a single parameter? ......... 145 10 What is dynamic SQL, and when is it useful in stored procedures? .................. 145 11 How can you improve the performance of a stored procedure? ........................ 145 12 How do you grant permissions to execute a stored procedure? ......................... 145 13 Can a stored procedure return multiple result sets? ............................................ 146 14 What is the difference between a stored procedure and a user-defined function? ..... 146
Page 10
15 How do you debug a stored procedure? ................................................................ 146 16 What are nested stored procedures? ....................................................................... 146 17 How do you view the source code of a stored procedure? .................................. 146 18 Can you use transactions within a stored procedure? ......................................... 147 19 How do you drop a stored procedure? ................................................................... 147 20 What are the best practices for writing efficient and maintainable stored procedures? ................................................................................................................ 147 CHAPTER 9: Triggers and Views ............................................................. 148 1 What is a database trigger, and what events can trigger its execution? ............. 151 2 How do you create a trigger in SQL? ...................................................................... 151 3 What is the difference between a BEFORE trigger and an AFTER trigger? ........... 151 4 In what scenarios are triggers commonly used? ................................................... 151 5 How can you enable or disable a trigger? .............................................................. 152 6 What are some potential drawbacks of using triggers?........................................ 152 7 How do you create a view in SQL? ......................................................................... 152 8 Can you update data through a view? If yes, what are the restrictions? ............ 152 9 What is the difference between a regular view and a materialized view? .......... 152 10 How can you update a materialized view? ............................................................. 153 11 What is a nested view, and how does it differ from a regular view? .................. 153 12 In what situations would you use an indexed view? ............................................ 153 13 How do views contribute to data security and access control? ........................... 153 14 Can you combine views with joins in a query? ..................................................... 153 15 How does recursion work in views, and what is its use case? ............................. 154 16 What is the impact of updating the underlying tables on views? ....................... 154 17 How can you handle updates on non-updatable views? ...................................... 154 18 How do views contribute to data abstraction and query simplification? ................ 154 19 Can you provide an example of a situation where a trigger would be useful?.. 154 20 How would you create an indexed view to improve query performance? .............. 155 CHAPTER 10: Normalization........................................................................ 156 1 What is database normalization, and why is it essential in database design? ............... 159 2 Explain the First Normal Form (1NF) and its requirements. ............................. 159 3 How does the Second Normal Form (2NF) differ from 1NF, and what problem does it address? .......................................................................................... 159 4 What is the Third Normal Form (3NF), and what types of dependencies does it eliminate? ........................................................................................................ 160 5 When should you consider moving to Boyce-Codd Normal Form (BCNF) instead of 3NF? .......................................................................................................... 160
Page 11
6 What is Fourth Normal Form (4NF), and what problem does it address? ............. 160 7 How does Fifth Normal Form (5NF) handle join dependencies? ...................... 160 8 What is denormalization, and in what situations is it appropriate to use? ....... 160 9 How does normalization help in avoiding insertion, update, and deletion anomalies? .................................................................................................................. 161 10 What is the purpose of functional dependencies in normalization? ................. 161 11 Can you have multiple candidate keys in a table, and how do they relate to normalization? ........................................................................................................... 161 12 How does normalization impact database query performance? ........................ 161 13 What are the potential drawbacks of denormalization? ...................................... 161 14 In what real-world scenarios is normalization crucial for data integrity? ........ 162 15 How can you decide on the level of normalization required for a specific database design? ........................................................................................................ 162 16 Can you provide an example of a table that violates the First Normal Form (1NF)? .............................................................................................................. 162 17 How would you convert the above table into 1NF? ............................................. 162 18 Explain the process of achieving Second Normal Form (2NF) in a table. ........ 163 19 What is a composite key, and when is it used in normalization? ....................... 163 20 How can normalization and denormalization be balanced in a database design? ..... 163 Chapter 11: Transaction ................................................................................... 164 1 What is a transaction in the context of a database? .............................................. 167 2 Explain the ACID properties of transactions. ....................................................... 167 3 What are the different states that a transaction can go through during its lifecycle? ...................................................................................................................... 167 4 How do you begin a transaction in SQL, and how do you end it? ..................... 168 5 What is the difference between an implicit transaction and an explicit transaction? ................................................................................................................ 168 6 Explain the concept of savepoints in transactions. ............................................... 168 7 What is a deadlock in transactions, and how can it be resolved? ....................... 168 8 What are the different isolation levels in transactions, and how do they affect data consistency and concurrency? .............................................................. 169 9 How can you handle errors within transactions to ensure proper rollback and recovery? ............................................................................................................. 169 10 What is the purpose of a transaction log in a database, and how does it aid in recovery? .......................................................................................................... 169 11 How can you implement a two-phase commit (2PC) protocol for coordinating distributed transactions? .................................................................. 169 12 What are the best practices for designing and managing transactions effectively? .... 170
Page 12
CHAPTER 12: Window Function and CTE ...........................................171 1 What are Window Functions in SQL, and how are they different from regular aggregate functions? .................................................................................... 174 2 Explain the PARTITION BY clause in Window Functions with an example. ........... 174 3 How do you calculate the cumulative salary for each department using Window Functions? .................................................................................................. 175 4 What is the purpose of the ORDER BY clause in Window Functions? ............ 175 5 How can you find the percentage of total sales for each product using Window Functions? .................................................................................................. 176 6 What is the difference between ROWS BETWEEN and RANGE BETWEEN clauses in Window Functions? ........................................................... 176 7 How do you find the lead and lag values for a column using Window Functions? .................................................................................................................. 177 8 Explain the concept of Recursive CTEs in SQL. ................................................... 177 9 How do you use a Recursive CTE to traverse a hierarchical table? .................... 178 10 How can you use a CTE to simplify a complex query? ........................................ 179 11 When would you use a CTE instead of a subquery? ............................................ 179 12 How can you use multiple CTEs in a single query? ............................................. 179 13 Can you use a CTE inside another CTE? ............................................................... 180 14 How do you perform aggregation on CTEs? ......................................................... 180 15 How do you calculate the running total for a column using Window Functions and CTEs? ................................................................................................ 181 16 How can you use a Window Function with a PARTITION BY clause to find the highest salary in each department? .......................................................... 181 17 How do you calculate the percentage change in sales compared to the previous month using Window Functions? .......................................................... 182 18 How can you use the RANK() function to find the top N employees with the highest salary? ..................................................................................................... 183 19 Explain the concept of a "rolling sum" using Window Functions. ..................... 184 20 How do you use the ROWS BETWEEN clause to calculate a "rolling sum"? .............. 184 21 What are the performance considerations when using Window Functions and CTEs in SQL? ..................................................................................................... 185 22 How can you use Window Functions and CTEs together in a single query to perform advanced analytical calculations? ....................................................... 185 23 How do you use Window Functions to find the top N products with the highest sales, considering ties? ................................................................................ 186 24 How can you calculate the average salary for each department while excluding the highest and lowest salaries using Window Functions? ............... 187
Page 13
25 How do you find the top N products with the highest sales for each month using Window Functions? .......................................................................... 188 26 What are the potential use cases for Recursive CTEs, and how do they work? ........... 189 27 How can you use a Recursive CTE to traverse a hierarchical table with unlimited nesting levels? .......................................................................................... 190 28 How can you use the SUM() function with PARTITION BY and ORDER BY to calculate the moving average of sales for each product? ........... 191 29 How do you use a CTE to simplify a query that involves multiple subqueries? .......... 192 30 How can you use the ROWS UNBOUNDED PRECEDING and ROWS UNBOUNDED FOLLOWING clauses in Window Functions? ........................ 193 31 How do you use a CTE to simplify a complex hierarchical query for an organizational chart? ................................................................................................ 194 32 What is the difference between the DENSE_RANK() and RANK() functions in Window Functions? ............................................................................ 194 33 How can you use a Window Function to find the percentage of sales contributed by each product compared to the total sales? .................................. 194 34 Can you use Window Functions without the PARTITION BY clause? If yes, what will be the result? .................................................................................. 195 35 How can you use the RANK() function with the PARTITION BY clause to find the top N employees with the highest salary within each department? .... 195 36 How do you use a Recursive CTE to calculate the total cost of a bill of materials for a product and all its components? ................................................... 197 37 What are some common performance optimization techniques for queries involving Window Functions and CTEs? ................................................ 197 38 How can you use the FIRST_VALUE() and LAST_VALUE() functions in Window Functions to retrieve the first and last values in a partition? .............. 197 39 How do you use Window Functions to calculate the difference between the sales of each product and the average sales of all products? ......................... 198 40 How can you use Window Functions to calculate the difference in sales between the current and previous months for each product? ............................ 199 CHAPTER 13: Deep Dive ................................................................................. 201 Difference between ROW_NUMBER(), RANK(), and DENSE_RANK() ............... 201 Difference between row_number vs rank vs dense_rank............................................ 205 Difference between VARCHAR and NVARCHAR in SQL Server? .......................... 206 What is difference between SQL, T-SQL and PL/SQL? ............................................... 208 Differences between SQL, T-SQL and PL/ SQL ........................................................... 210 How to check for Null in SQL Query? ........................................................................... 212 Difference between CAST, CONVERT, and PARSE function in Microsoft SQL Server? ... 215 Difference between UNION vs UNION ALL in SQL .................................................. 220
Page 14
Difference between UNION and UNION ALL command in SQL ............................ 225 Difference between table scan, index scan, and index seek in SQL Server Database ............ 227 Difference between table scan, index scan, and index seek in Database ................... 227 Difference between table scan, index scan, and index seek in SQL ........................... 230 Difference between ISNULL() and COALESCE() function in SQL? ........................ 231 Difference between ISNULL() vs COALESCE() in SQL Server ................................. 232 How to Find Nth Highest Salary in MySQL and SQL Server? ................................... 236 Difference between VARCHAR and CHAR data type in SQL Server? ..................... 238 Similarities between CHAR vs. VARCHAR in SQL .................................................... 240 Difference between WHERE and HAVING clause in SQL? Example ...................... 243 Difference between WHERE vs. HAVING in SQL ...................................................... 244 Difference between Primary key vs Candidate Key in SQL Database? ..................... 246 Difference between Correlated and Non-Correlated Subquery in SQL .................... 247 Difference between Correlated and Regular Subquery in SQL .................................. 248 Difference between Self and Equi Join in SQL .............................................................. 252 How to remove duplicates from a table? ....................................................................... 253 How to Find Customers Who Never Order using EXISTS in SQL ........................... 260 How to find Duplicate emails in a table? ....................................................................... 261 CHAPTER 14: Conclusion ................................................................ 265
Page 15
(This page has no text content)
Page 16
— 1 — Overview s a Java developer who has cleared SQL interviews, I can attest that SQL interviews are not easy, given the vast nature of SQL and the variety of concepts and topics it covers. When I was preparing for Java interviews, I was looking for a resource where I learn and prepare SQL questions from a programmer’s perspective rather than a DBA, but I couldn’t find any. Grokking the SQL Interview is my effort to fill that gap and become an excellent resource for anyone looking to master SQL and prepare for SQL interviews. Whenever I prepare for Java Interview, I always prepare about SQL and Linux; these are everywhere. That’s why I decided to cover essential topics from an interview perspective when I thought to write about this book. The book covers a wide range of topics, starting with the basics of SQL and database design, and progressing to more advanced topics like SQL queries, joins, indexes, group-by and aggregate functions, stored procedures, triggers and views, database normalization, transactions, window functions, and common interview questions. One of the best things about this book is that it includes many real-world SQL questions commonly asked in job interviews. This means that by studying the questions and answers in this book, you will be well-prepared for any SQL interview. A
Page 17
GROKKING THE SQL INTERVIEW — 2 — Overall, I hope Grokking the SQL Interview is an excellent resource for anyone looking to master SQL and prepare for SQL interviews. I have tried my best to cover all the essential topics you need to know to succeed in SQL interviews. Whether you are a beginner or an experienced SQL developer, you can use this book to quickly revise and prepare for SQL questions for software developer and Data Science interviews. Why Prepare for SQL and Database for Interviews? Many Java developers, particularly experienced developers with a couple of years of experience, think that it's not necessary to prepare for SQL questions, only to fluff their chances. It doesn’t matter how many years of experience you have in SQL and Database; you must prepare for interviews. Why? I suggest preparing because when you work on a vast technology like Database and SQL, you work on a particular area. It’s almost impossible to learn all the areas of a specific framework. For example, if you work in a Java application that uses MySQL on the backend, you are most likely exposed to writing queries and stored procedures. Still, you may or may not be involved in the database design process. And, believe it or not, interviews are almost always very different from real jobs. Interviewers expect you to know everything about the technology, even if certain areas are never used in any project, like normalization and database design in this case. If your aim is to clear the interviews because you need that job then you don’t have any choice; you cannot argue what is right or what is wrong, the best approach is to prepare hard and prepare well and that’s where this book can help you.
Page 18
OVERVIEW — 3 — While learning anything quickly is impossible, this book provides a nice overview of almost all essential SQL and Database concepts. You can easily finish the book in a few hours or few days, depending on how much time you spend daily. If you are going for a Software Developer interview or Data Science Interview, where SQL and Database is mentioned as a desired skill then I highly recommend you to go through these questions before attending any telephonic or face-to-face interview. While there is no guarantee that the Interviewer will ask any question from this book, by going through the book, you already know most of the SQL and Database concepts which you are expected to know. How to prepare SQL for Interviews? In order to best prepare for Software Engineer and Data Science SQL Interviews, you need to have a solid understanding of SQL concepts and their a couple of popular databases like MySQL, Oracle, Microsfot SQL Server, and PostgreSQL Preparing for SQL interviews requires a combination of theoretical knowledge and practical experience. Here are some tips to help you prepare for SQL interviews: • Review SQL basics Ensure you have a solid understanding of SQL fundamentals, including data types, operators, and syntax. • Practice SQL queries Work on creating and executing SQL queries involving filtering, sorting, grouping, and joining data from multiple tables.
Page 19
GROKKING THE SQL INTERVIEW — 4 — • Familiarize yourself with popular database management systems. Get familiar with popular database management systems such as MySQL, Oracle, and SQL Server. • Learn about database normalization. Understand the basic principles of database normalization, which is organizing data to minimize redundancy. • Understand data modeling Learn about data modeling, which involves creating a conceptual model of the data to be stored in a database. • Brush up on statistics and data analysis. Many SQL interviews will involve statistical and data analysis questions, so it's important to understand these topics well. • Practice with sample SQL interview questions There are many resources available online where you can find sample SQL interview questions to practice with. Remember that SQL interviews are not just about memorizing syntax and queries but also about being able to think critically and solve complex problems. With practice and preparation, you can develop the skills needed to ace your SQL interview. If you are short of time, then there is no choice but to go through the question as soon as possible so that you can revise the essential concepts and at least have some idea about it. Reviewing this book will not only help you gain both confidence and knowledge to answer the questions, but more importantly, it will allow you to drive the Java interview in your favor. This is the single most important tip I can give you as a Java developer. Always remember your answers drive interviews, and these questions will empower you to drive the Interviewer to your stronger areas.
Page 20
OVERVIEW — 5 — All the best for the SQL interview, and if you have any questions or feedback, you can always contact me on Twitter at javinpaul or comment on my blogs Javarevisited and Java67. Which SQL and Database topics to Prepare for Interviews? These are the key SQL and database topics which you need to prepare for any technical interviews: • SQL and Database Basics • SQL JOINs • SQL Queries from Interviews • Indexes • GROUP BY • Aggregate Functions • Stored Procedure • Trigger and View • Advanced SQL Questions • Conclusion These are also the topics which you need to prepare Data Scientist interviews, which means you can kill two birds in one stone. I mean, by preparing for Software development interview you can also get yourself ready for potential Data Scientist jobs.
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List