Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Master SQL interviews (Top Interview questions & answers)
Rating: 4.5 out of 5(46 ratings)
559 students

Master SQL interviews (Top Interview questions & answers)

Learn Most Common SQL interview questions and answers with detailed explanations & hands on examples
Created byBiswajit Nanda
Last updated 8/2022
English
English [Auto],

What you'll learn

  • Will be able to revise all important SQL concepts like RDBMS, Joins, Indexes, various constraints etc.
  • Will learn top SQL interview questions and their answers.
  • Will learn SQL programming questions and answers like top nth salary from table and ranks
  • Multiple approaches to tackle the same interview question

Course content

1 section86 lectures2h 13m total length
  • Question 1: What is a Database?0:10

    Define a database as an organized, structured collection of information or data stored in a computer system, enabling efficient data organization and retrieval.

  • Question 2: What is the difference between a database and DBMS?0:47

    Differentiate a database from a dbms: a database is a data collection, while a dbms is the software that manipulates, stores, and retrieves data; write select queries and update statements.

  • Question 3: What is the difference between DBMS and Relational DBMS?0:32

    Explain how a database management system uses software to manipulate, store, and retrieve data, and how a relational DBMS stores data in tables and defines relationships.

  • Question 4. What are DDL, DML and DCL statements?0:52

    Explore ddl, dml, and dcl in sql, showing ddl definitions with drop, alter, rename; dml data manipulation with insert, update, delete, select; and dcl access control with grant, deny, revoke.

  • Question 5: What is SQL?0:52

    Explore the roles of data definition language, data manipulation language, and data control language, with examples like create, drop, alter, stored procedures, triggers, and grants.

  • Question 6: How do you create a table?1:43

    Learn how to create a table in SQL, specify a table name and columns with data types, and define a primary key to uniquely identify records.

  • Question 7: What is the difference between CHAR and VARCHAR2 datatype in sql2:21

    Explain the difference between char and varchar2 data types in SQL, contrasting fixed-length storage with char and variable-length storage with varchar2, and illustrate using length measurements.

  • Question 8: How do you create a table from another table?3:48

    Learn how to create a new table from an existing one using select into, duplicating both structure and data, with Oracle-specific alternative methods.

  • Question 9: How do you insert values into a table?3:59

    Learn how to insert values into a table using insert statements, specify column names to control order, and handle partial column lists or select-based inserts.

  • Question 10: Can you insert data into the same table by taking data from it?1:13

    Demonstrates inserting into the same table by selecting from it; a primary key prevents data insertion, as five rows become ten in the example.

  • Question 11: What will happen if you insert a bigger value into a varchar column1:03

    Inserting a value larger than the varchar column length triggers an error 'value too large for column' in Oracle, and the insert is terminated with no data stored.

  • Question 12: How do you select data from a table?1:30

    Master SQL data retrieval by selecting all columns with select * from a table or specific columns such as first name, salary, position, and last name to improve readability.

  • Question 13: How do you select data from a table using WHERE clause?2:02

    Explore how to use the where clause to filter data with exact matches, pattern matching with like, and comparisons such as greater than to retrieve records.

  • Question 14: How do you delete all data from a table?0:41

    Learn how to delete all data from a table in SQL Server using delete from, with an example deleting 60 rows from the employee table, leaving it empty.

  • Question 15: How do you delete data from a table based on a condition?1:16

    Delete data from a table using a conditional where clause, counting rows before and after removing records such as Becky to show how deletions reduce the total.

  • Question 16: What is the difference between DELETE and TRUNCATE statements?1:10

    Compare delete and truncate in SQL. Delete logs each row in the transaction log, while truncate removes data by deallocating data pages, making it faster.

  • Question 17: How do you drop a table?1:47

    Learn how to drop tables in SQL Server, including dropping multiple tables in a single statement. After dropping, queries from those tables show an invalid object.

  • Question 18: What is the difference between Delete and Drop?1:34

    Learn the difference between delete and drop in SQL. Delete removes rows from a table, optionally with a condition, while drop removes the table entirely from the database.

  • Question 19: What are constraints and what is their importance?1:46

    Enforce data integrity by constraints that govern allowed values, ensuring accuracy and reliability; include unique constraints, primary keys, foreign keys, and default handling when values are missing.

  • Question 20: What is a Primary Key?1:12

    Define a primary key that uniquely identifies each row, can be a single or composite key, and must contain unique values, noting there is typically only one primary key.

  • Question 21: How do you create a Primary key while creating a table?0:53

    Create a primary key while creating a table in SQL, and verify the key appears in the newly created table.

  • Question 22: How do you create a table level Primary Key?0:44

    Learn how to define a table-level primary key by specifying the columns in a primary key constraint, as shown with the student diary and name columns.

  • Question 23: How do you create a Unique Key while creating a table?1:11

    Discover how to define a unique key alongside a primary key when creating a table, using an example where student_id is the primary key and ssn is a unique key.

  • Question 24: How do you create a table level Unique Key?1:29

    Learn to create a table level unique key using a unique constraint on selected columns, with the option to use a primary key for the same columns.

  • Question 25: What is the difference between a Primary Key and Unique Key?2:30

    Primary key enforces non-null, unique values and allows only one per table. Multiple unique keys can exist on a table and may accept nulls, but both prevent duplicates.

  • Question 26: How do you create a Check constraint while creating a table?1:53

    Learn how to define a check constraint at table creation to enforce age values greater than 25, preventing invalid inserts and triggering a check constraint violation error when violated.

  • Question 27: How do you create a table level check constraint?2:49

    Create a table-level check constraint by listing all involved columns and defining a condition. This approach handles multiple criteria, such as age >= 18.

  • Question 28: Create a check constraint to restrict values to a range1:10

    Learn to create a check constraint that restricts values to a range between 15 and 25, enforce it for inserts, and see violations when values fall outside the range.

  • Question 29: Create a check constraint to have name starting with A2:06

    Master SQL interviews: learn to create a check constraint that enforces a first name starting with A, and validate inserts with practical examples.

  • Question 30: How do you create a foreign key on a table?2:44

    Define a foreign key on the student table that references the city code in the city table, enforcing referential integrity by ensuring the child city matches a valid city.

  • Question 31: How do you create a table level foreign key?1:46

    Learn to define a table-level foreign key after listing all columns in the student table, name the constraint (for example, fk_city), and reference city(city_code) to enforce referential integrity.

  • Question 32: What is meant by a nullable column?1:00

    Explore what a nullable column means, showing that the columns allow null values and can store normal values, demonstrated with a salary column and a select query.

  • Question 33: What are aggregate functions?0:25

    Explore how aggregate functions perform calculations on a set of values and return a single value, with count as an example that returns the raw count of a table.

  • Question 34: Write a SQL statement to count the total number of rows of a table0:42

    Learn to count the total rows in a table efficiently by using a simple select count(*) statement, avoiding scanning all records, especially for tables with millions of rows.

  • Question 35: Write a SQL statement to count number of rows matching a condition0:57

    Write a SQL statement to count rows that satisfy a given condition using like patterns, such as first names starting with e or g, and interpret the results.

  • Question 36: Write a SQL statement where column matches with a string value(LIKE1:29

    Learn to use the SQL LIKE operator to match string values with starts with, ends with, and contains patterns, filtering rows by the first name.

  • Question 37: How do you calculate the average,minimum and maximum salary from em0:42

    Discover how to calculate average, minimum, and maximum salaries using sql aggregate functions such as avg, min, and max on the salary data.

  • Question 38: How do you calculate total salary for employees grouped by employee1:18

    Learn how to calculate each employee’s total salary by grouping by employee and summing monthly salaries with a SQL select that returns the employee name and the total salary.

  • Question 39: How do you select data in a table in sorted order(Asc & and desc)1:16

    Learn to select data in a table in sorted order, using ascending by default and applying descending to view results, with examples showing how to sort data.

  • Question 40: How do you specify a condition with a GROUP BY clause?2:03

    Learn how to apply conditions to grouped data with the group by clause and having, filtering annual salaries by name patterns and salary thresholds.

  • Question 41: Can you have both HAVING and WHERE clauses together?1:06

    Discover that where and having clauses can co-exist in a single select statement, demonstrated by an example that groups by a name and applies a salary condition.

  • Question 42: Write a query to display schema of a table1:43

    Use information_schema views to display a table’s columns, data types, and max length, and leverage the sb_help system stored procedure or the describe command to view schema details.

  • Question 43: Alter a table to add a new column to a table0:56

    Discover how to alter an existing table to add a new column using alter table add column, define the column, and observe how existing data remains intact.

  • Question 44: How do you change the data type of a column of a table1:18

    Master SQL interviews explains how to change a column's data type by altering the table, specifying table name and column, then executing and verifying the change.

  • Question 45: How do you drop a column from a table?0:54

    Drop a column from a table using the drop column command, then verify by describing the table schema to confirm the column no longer exists.

  • Question 46: What is a Join?1:10

    Learn how joins combine two or more tables based on related data to retrieve customer and order details, including customer id, customer name, contact name, country, and order date.

  • Question 47: Explain different types of joins0:49

    Explore different types of joins in SQL, including left join, right join, and full join, and see how they combine data from two sources.

  • Question 48: What is the difference between an outer join and inner join?2:36

    Explain the difference between inner join and outer join in SQL interviews by showing how matching and non-matching rows are returned from two tables, using left and right joins.

  • Question 49: What is the difference between Left Inner Join and Left Outer join?1:28

    Explain the difference between left inner join and left outer join, showing that left joins return all left rows with matching right rows and nulls for nonmatches, using a student–city example.

  • Question 50: What is Cross Join? Where is it useful?2:40

    Explain cross join as the Cartesian product of two tables, producing all row combinations. Use it to generate large data sets by combining two tables, such as students and city.

  • Question 51: What is Full Join?1:40

    Learn how a full outer join returns matching rows and nonmatching rows from both tables, with nulls on missing sides, illustrating how full join combines all records.

  • Question 52: What is Self Join?2:40

    Self joins show how a table is joined to itself to retrieve the manager name by matching the employee's manager id in the same data, using aliases.

  • Question 53: Write a sql statement to display current date and time0:30

    Execute a select statement to display the current date and time using a system function. See how the function returns the system date and time with example values.

  • Question 54: Write a sql statement to display the server and database name0:35

    Write a SQL statement to display the server and database name using a function and executing a select command.

  • Question 55: Write a sql statement to display the user name0:27

    Write a sql statement to display the user name using a built-in function that reveals the request owner information.

  • Question 56: Write a sql statement to display the number of tables present in db1:50

    Query information_schema.tables to count distinct table names in the database. It shows the total number of tables as 20.

  • Question 57: Write sql to display the second highest salary from employee table2:02

    Learn how to display the second highest salary from the employee table in SQL by excluding the maximum with a nested max query.

  • Question 58: Write a SQL query to return a substring from a string1:36

    Explore how to use the substring function in SQL to extract part of a string by specifying a start position and length, with India as an example.

  • Question 59: Write a SQL query to return the no of characters of a given string0:41

    Master SQL interviews cover computing a string's length with the length function in SQL; see how the string 'India' yields 5 characters.

  • Question 60: Write SQL to return the numeric position of a character in a string1:05

    Learn to use the cat index function to find the numeric position of the first occurrence of a character in a string, with examples like locating 'G' in a name.

  • Question 61: Write a SQL statement to display distinct salaries from a table0:54

    Learn how to display unique salaries from a table's salary column using the distinct keyword in a select statement.

  • Question 62: How do you concatenate two strings in sql?1:08

    Explore two ways to concatenate strings in SQL: using the plus operator and using the built-in CONCAT function, with example queries showing equivalent results.

  • Question 63: Create a empty table with the same structure as another table1:20

    Question 63 teaches how to create an empty table with the same structure as another table using select into and a false where clause.

  • Question 64: SQL to return first 3 characters(right and middle also) of a string1:37

    Learn how to return the first three characters of a string in SQL using left and substring, with examples from London and extracting middle characters.

  • Question 65: What are indexes? Why they are used?1:59

    Learn how indexes speed data retrieval by creating an index on a table, illustrated with a simple number and names table and the create index syntax.

  • Question 66: What are clustered indexes?2:28

    Explain what a clustered index is, how it sorts table data in order, and how a primary key creates a clustering index. Learn to create one with the cluster keyword.

  • Question 67: What are non-clustered index?2:28

    Explore non-clustered indexes, an index structure separate from table data, including composite indexes, that boost query performance on frequently used columns, with steps to create and verify them.

  • Question 68: What is a Unique index? Write a SQL to create one2:29

    learn how unique indexes prevent duplicates to protect data integrity, compare them with unique constraints, and practice creating a unique index with sql syntax.

  • Question 69: What is a view? Write a sql statement to create a view1:43

    Learn how a SQL view serves as a virtual table built from a query, created with create view view_name as select ..., and queried like a regular table.

  • Question 70: Write a sql statement to display the number of views present1:40

    learn to write a sql statement that displays user defined views by querying information_schema.tables where table_type = 'VIEW' and excluding system schemas.

  • Question 71: What is a subquery? Why is it used?2:12

    Explains what a subquery is and why it's used to simplify complex queries, offering an alternative to joins to list customers who placed orders.

  • Question 72: Write a query to remove spaces present in a string from sides1:34

    Discover how to remove spaces from the left, right, and both sides of a string in SQL, with examples illustrating left trim, right trim, and full trim.

  • Question 73: What is the difference between Union and Union all?2:04

    Compare union and union all by showing how they combine data from two tables, with union removing duplicates and union all preserving them.

  • Question 74: What is EXCEPT or MINUS operator?1:49

    Explore how the EXCEPT (or MINUS) operator in SQL returns the difference between two sets, showing rows in the first table not in the second.

  • Question 75: What is Intersect operator?0:55

    Explore the intersect operator inSQL, demonstrated with select examples and table relationships to show how it highlights common results across multiple data sets.

  • Question 76: What are temp tables in SQL Server?1:06

    Explore temp tables in SQL Server, their lifespan and growth, and how naming with a hash character signals temporary objects during creation.

  • Question 77: What are global temp tables in SQL?1:13

    Explore how global temporary tables work in SQL, including creation with a double symbol, visibility across all connections, and automatic drop when the last connection ends.

  • Question 78: How to get nth maximum salary from a table?3:13

    Learn to retrieve the nth highest salary by selecting the top n salaries in descending order and taking their minimum to yield the third, fourth, or fifth highest.

  • Question 79: Nth maximum salary when there are duplicate salaries4:22

    Learn how to compute the nth distinct maximum salary by selecting distinct salaries, ordering them by salary descending, and taking the minimum of the top n distinct values.

  • Question 80: What is COALESCE function in SQL?1:36

    Learn how the coalesce function returns the first non-null value in a list and how it replaces nulls in a column or query results.

  • Question 81: What is OLTP?1:24

    Define OLTP as online transaction processing system that handles real-time, concurrent financial transactions over the internet with emphasis on speed and atomicity, ensuring transactions either complete or fail.

  • Question 82: What is the difference between OLTP and OLAP systems?1:21

    Explain the difference between OLTP and OLAP systems: OLTP handles many online transactions with atomic, fast processing; OLAP emphasizes data analysis via data warehouses and cubes.

  • Question 83: What are the different types of relationship existing in RDBMS?1:02

    Identify the three relationship types in RDBMS: 1 to 1, 1 to many, and many to many.

  • Question 84: How to create a temp table in SQL Server?0:41

    Learn how to create temp tables in SQL Server using a leading #, compare temporary and permanent tables, and understand that temp tables are dropped when the connection ends.

  • Question 85: How to write a CASE statement in SQL?2:24

    Learn to write a case when statement in sql to classify salaries as low or high based on salary < 2500, displaying first name, salary, and salary type.

  • Question 86: How do we delete duplicate rows?1:52

    Delete duplicate rows in the employee salary 2022 table by grouping by name, filtering with having count(*) > 1, and deleting those names.

Requirements

  • Basic SQL knowledge will be beneficial

Description

This course has been intended for programmers and testers who want to master SQL interview questions and answers.


Most of the modern applications  create data in a backend database and hence knowing SQL is an essential skill for everyone. The course covers a number of questions and answers in the following areas


1) Databases

2) Various types of Database Management system

3) Different types of SQL statements - DDL, DML and DCL statements

4) SQL introduction

5) Creating tables

6) SQL Data types

7) SELECT INTO operations

8) Conditional SELECT operations

9) DELETE ALL and Conditional DELETE operations

10) DELETE and TRUNCATE operation comparison

11) DROP table operations

12) Data Integrity and constraints

13) Column level and Table level primary Keys

14) Creating Unique keys

15) Various types of check constraints

16) Nullable columns

17) Aggregate functions

18) SQL statements to address different goals

19) Displaying schema of tables

20) What are JOINS?

21) Different types of JOINS - Inner Join, Left Outer, Right Outer and Full Outer Joins

22) What is SELF and Cross Joins?

23) Displaying System Date and time

24) Displaying server and database names

25) Various string operations - Substring, CHARINDEX, Concatenation etc

26) Creating an empty table from an existing table

27) LEFT, RIGHT operations

28) What are indexes? 

29) Describe Clustered indexes

30) Non-clustered indexes and difference from Clustered indexes

31) Describe Unique Indexes

and many more ...



Who this course is for:

  • This course has been designed for Data scientists, programmers and testers looking to master SQL interviews