10 Useful SQL Commands for Data Analysts - Howsnip

10 Useful SQL Commands for Data Analysts

Structured Query Language (SQL) is an essential tool for every data analyst/engineer. It allows analysts to extract, aggregate, update, and manage data efficiently. The below mentioned SQL commands are fundamental for querying, analyzing, and transforming data.

As a data analyst, your core responsibilities include gathering, cleaning, analyzing, and interpreting data to help companies make informed and quick decisions. SQL language always empowers you to do this with precision and speed. SQL is often the backbone of BI tools like Power BI, Tableau, and Looker for dashboard creation.

Pro Tip: Start with commands like SELECT, JOIN, GROUP BY, and WHERE. 

Below, you’ll find 10 of the most useful and commonly used SQL commands, with practical examples and tips.

  1. SELECT
  2. WHERE
  3. ORDER BY
  4. GROUP BY
  5. HAVING
  6. JOIN
  7. COUNT, SUM, AVG, MIN, MAX
  8. LIMIT
  9. IN & BETWEEN
  10. UPDATE & DELETE

1. SELECT

The purpose of SELECT command is to retrieve data from a table. The SELECT statement is the fundamental SQL command to fetch data from one or more tables.

Syntax - SELECT * FROM employees;

Select command - howsnip

2. WHERE

The purpose of WHERE command is to filter records based on specified conditions such as salary thresholds, specific text, or date ranges.

Syntax - SELECT name, salary FROM employees WHERE salary > 10000;

Where command - howsnip

3. ORDER BY

The purpose of ORDER BY command is to sort the results by one or more columns. Adding DESC orders the data in descending order; use ASC for ascending (default).

Syntax - SELECT name, hire_date FROM employees ORDER BY hire_date DESC;

Order By Command - howsnip

4. GROUP BY

The purpose of GROUP BY command is to aggregate data by specified groups, such as counting employees per department.

Syntax - SELECT department, COUNT() FROM employees GROUP BY department;

Group By Command - howsnip

5. HAVING

The purpose of HAVING command is to filter groups after aggregation, such as departments with an average salary above a certain value.

Syntax - SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 10000;

Having Command - howsnip

6. JOIN

The purpose of JOIN command is to combine rows from two or more tables based on a related column. The example below connects employee names with their department names.

Syntax - SELECT e.name, d.department_name FROM employees e JOIN departments d ON e.department_id = d.id;

Join Command - howsnip

7. COUNT, SUM, AVG, MIN, MAX

The purpose of COUNT/SUM/AVG/MIN/MAX command is to aggregate calculations on data columns.

Syntax - SELECT COUNT() FROM employees;
Syntax - SELECT AVG(salary) FROM employees;

Count command - howsnip

8. LIMIT

The purpose of LIMIT command is to restrict the number of rows returned. This command is also helpful for sampling data or previewing the top results without retrieving the entire table.

Syntax - SELECT * FROM employees LIMIT 10;

Limit command - howsnip

9. IN & BETWEEN

The purpose of IN/BETWEEN command is to filter queries for multiple values or within specified ranges.

Syntax - SELECT name FROM employees WHERE department IN ('HR', 'Finance', 'Lab');
Syntax - SELECT name FROM employees WHERE hiring_date BETWEEN '2025-04-20' AND '2025-05-20';

In command - howsnip

10. UPDATE & DELETE

The purpose of UDPATE/DELETE command is to modify or remove records. The UPDATE command alters the existing data where as the DELETE command removes data from the table.

Syntax - UPDATE employees SET salary = salary * 1.1 WHERE performance = 'Excellent';
Syntax - DELETE FROM employees WHERE status = 'Resigned';

Delete Command - howsnip

Make sure that you should specify a WHERE clause to avoid unintentional changes.

There are many online SQL editors available, but all the screenshots in this guide use Programiz SQL Online Compiler, one of the most reliable and user-friendly options out there.