“Master Your SQL Interview: The Ultimate 2024 SQL Cheat Sheet with Essential Queries and Topics for Success” (Part 1)

Sagardhiman
3 min readDec 16, 2023
SQL Cheat Sheet
SQL Cheat Sheet

Welcome to the gateway of SQL mastery! If you’re gearing up for an SQL interview in 2024 or aiming to sharpen your database skills, you’ve landed on the right page. In this comprehensive blog, we’ve curated the ultimate SQL cheat sheet surround all the crucial queries and topics essential for practicing your interview.

If you follow the below mentioned steps there is no need to search any other topics left, we are now discussing all the topics, So start with the basics.

  1. SQL SELECT DISTINCT:

The SELECT DISTINCT statement is used to return only distinct (different) values.

 SELECT DISTINCT Country FROM Customers;

2. SQL AND, OR Operator:

The AND operator is used to filter records based on more than one condition, like if you want to return all customers from Spain that starts with the letter ‘G’.

SELECT *
FROM Customers
WHERE Country = 'Spain' AND CustomerName LIKE 'G%';

The OR operator is used to filter records based on more than one condition, like if you want to return all customers from Germany but also those from Spain.

SELECT *
FROM Customers
WHERE Country = 'Germany' OR Country = 'Spain';

3. The NOT Operator:

The NOT operator is used in combination with other operators to give the opposite result, also called the negative result.

In the below select statement below we want to return all customers that are NOT from Spain.

SELECT * FROM Customers
WHERE NOT Country = 'Spain';

4. SQL NULL, NOT NULL Values:

IS NULL operator is used to test for empty values (NULL values).

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;

The IS NOT NULL operator is used to test for non-empty values (NOT NULL values).

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;

5. SQL aggregate function:

An aggregate function performs a calculation on a set of values, and returns a single value.

The MIN()/MAX() function returns the smallest/largest value of the selected column.

SELECT MIN(Price)
FROM Products;

The COUNT() function returns the number of rows that matches a specified criterion.

SELECT COUNT(*)
FROM Products;

6. SQL LIKE Operator:

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';
Possible SQL LIKE patterns
Possible SQL LIKE patterns

7. SQL CASE Expression:

In simple terms, the SQL CASE expression is a way to perform conditional logic in a query. It allows you to evaluate a condition and return a specific value based on that condition. Think of it like an “if-then-else” statement in SQL.

Below is the simple and real time example.

Let’s say you have a table called employees with columns employee_id, employee_name, and salary. You want to categorize employees based on their salary into three groups: "Low Income," "Medium Income," and "High Income."

SELECT
employee_name,
salary,
CASE
WHEN salary < 30000 THEN 'Low Income'
WHEN salary >= 30000 AND salary < 60000 THEN 'Medium Income'
ELSE 'High Income'
END AS income_category
FROM
employees;

Note:

If you want to learn about remaining topics(Part 2) for the above SQL cheat sheet or need to learn about topics of Php, Laravel, Javascript, Mysql, Next Js, Node Js in detail, feel free to comment below and subscribe to the newsletter for latest updates.

Thanks!

🤝🏻 Connect with Me on LinkedIn, Do also Follow on Twitter

--

--