Top SQL Interview questions cheatsheet

Hello friends, If you are going to attend an interview where you expect SQL related questions, then you should definitely check out the below SQL Interview cheatsheet.

This Cheatsheet contains the frequently asked questions in SQL which every SQL professional should be aware. Bookmark this page and Go through these to instantly brush up the basics before attending any SQL interview

1. Basic SQL Queries
  • How to retrieve all column's data from a table:
    SELECT * FROM table_name;
  • How to retrieve distinct values from a table's column:
    SELECT DISTINCT column_name FROM table_name;
  • How to retrieve top N records from a table:
    SELECT * FROM table_name LIMIT N;
2. Filtering and Sorting:
  • How to filter data where a column equals a certain value?
    SELECT * FROM table_name WHERE column_name = value;
  • How to filter rows where the column value is within a given data range:
    SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • How to retrieve rows with NULL values in a column?
    SELECT * FROM table_name WHERE column_name IS NULL;
  • How to sort result set in ascending or descending order:
    SELECT * FROM table_name ORDER BY column_name ASC/DESC;
3. Aggregate Functions:
  • How to count total rows?
    SELECT COUNT(*) FROM table_name;
  • How to calculate average, sum, min, max?
    SELECT AVG(column_name), SUM(column_name), MIN(column_name), MAX(column_name) FROM table_name;
  • How to group and calculate aggregates:
    SELECT column_name, AVG(salary) FROM table_name GROUP BY column_name;
4. Joins:
  • Explain INNER, LEFT, RIGHT, FULL joins

    INNER: Retrieves common rows from both tables.
    LEFT: Retrieves all rows from the left table and matching rows from the right.
    RIGHT: Retrieves all rows from the right table and matching from the left.
    FULL: Retrieves all rows from both tables.

  • How to retrieve data from multiple tables?
    SELECT * FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
5. Subqueries:
  • How to use a subquery to retrieve data?
    SELECT * FROM table_name WHERE column_name IN (SELECT column_name FROM another_table);
  • How to compare values between tables?
    SELECT * FROM table1 WHERE column_name = (SELECT column_name FROM table2 WHERE condition);
6. Data Modification:
  • How to Insert a new record into the table?
    INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
  • How to Update an existing records into the table?
    UPDATE table_name SET column_name = new_value WHERE condition;
  • How to delete records from the table
    DELETE FROM table_name WHERE condition;
7. Database Table Design Concepts
  • Explain the differences between Primary key and Foreign key
    Primary key uniquely identifies a record, while a foreign key links to another table's primary key.
  • Design a table schema
    Create and explain a table with appropriate columns, primary keys, and foreign keys.

Content is copyrighted © www.123mylist.com