SQL FUNDAMENTALS

SQL FUNDAMENTALS

SQL stands for Structured Query Language. It is used to communicate with relational databases. A Data Analyst commonly uses SQL to retrieve, filter, summarize, combine and analyze data.

1. What is SQL?

SQL stands for Structured Query Language. It is used to communicate with relational databases. A Data Analyst commonly uses SQL to retrieve, filter, summarize, combine and analyze data.

2. Why does a Data Analyst need SQL?

Real business data is often stored in databases rather than in one Excel file. SQL lets an analyst ask business questions directly from that data: revenue, customers, orders, employee counts, trends, top products and many other metrics.

3. SQL vs MySQL

SQL MySQL
A language used to work with relational databases. A relational database management system (RDBMS) that can execute SQL.
Defines statements such as SELECT, INSERT and UPDATE. Provides the database engine/environment in which those statements run.

4. Database, Table, Row and Column

Term Simple Meaning Example in Our Dataset
Database Container that holds related tables. company_db
Table Structured collection of related data. employees
Row One record. Rahul's employee record
Column One attribute/field. salary

5. SQL Command Categories

Category Main Commands
DDL CREATE, ALTER, DROP, TRUNCATE
DML INSERT, UPDATE, DELETE
DQL SELECT
DCL GRANT, REVOKE
TCL COMMIT, ROLLBACK, SAVEPOINT

6. Basic SQL Rules

  • Statements normally end with a semicolon (;).
  • SQL keywords are commonly written in uppercase for readability, although MySQL is generally case-insensitive for keywords.
  • Text values are written inside single quotes (' ').
  • SQL formatting matters for readability, especially when queries become longer.

Important definitions

hhhh

Syntax

Use this general pattern as a reference:

HTML
example

Examples

SELECT statement

EXAMPLE 1
SELECT * FROM employees;
ResultDisplays all columns and all records from the employees table.

WHERE clause

EXAMPLE 2
SELECT * FROM employees WHERE salary > 50000;
ResultDisplays employees whose salary is greater than 50000.

INSERT statement

EXAMPLE 3
INSERT INTO employees (name, salary) VALUES ('Rahul', 45000);
ResultAdds a new employee record to the employees table.

UPDATE statement

EXAMPLE 4
UPDATE employees SET salary = 55000 WHERE name = 'Rahul';
ResultUpdates Rahul's salary to 55000.

DELETE statement

EXAMPLE 5
DELETE FROM employees WHERE name = 'Rahul';
ResultDeletes Rahul's record from the employees table.

ORDER BY

EXAMPLE 6
SELECT * FROM employees ORDER BY salary DESC;
ResultDisplays employees from highest salary to lowest salary.

COUNT function

EXAMPLE 7
SELECT COUNT(*) AS total_employees FROM employees;
ResultReturns the total number of employees.

GROUP BY

EXAMPLE 8
SELECT department, COUNT(*) AS total FROM employees GROUP BY department;
ResultShows the number of employees in each department.
Try it yourself

Expected output

A Profile heading followed by a paragraph.

Note

Tip

Common mistakes