Skip to main content

Introduction to SQL

SQL Structured Query Language is a standard programming language used to manage and manipulate relational databases. It allows users to store, retrieve, update and delete data in a structured format. SQL became a standard of the American National Standards Institute (ANSI) in 1986 and of the International Organization for Standardization (ISO) in 1987.

note

Key Features of SQL: Data Querying: Retrieve data from one or more tables using commands like SELECT.

DML (Data Manipulation Language): Add, update, or delete records using INSERT, UPDATE, and DELETE.

DDL (Data Definition Language): Define database structures using CREATE, ALTER, and DROP.

DCL ( Data Control Language): Control access and permissions with GRANT and REVOKE.

TCL (Transactional Control Language): Controls transactions using COMMIT and ROLLBACK.

https://github.com

Diagram introducing SQL concepts

success

Let's talk about the history of storing data, it all started with physical files and shelves. Later, companies started using Excel or Access. These tools have limitations when it comes to handling high data volumes.

Then, companies started developing database management systems like SQL, PostgreSQL, and MySQL.

Databases are of two types: SQL(Relational, Analytical OLAP) and NoSQL(key value, Graph, Document) mainly used for unstructured dataset. This NoSQL provides more flexibility over Relational as it doesn't have to follow schemas.

Schema is named collection of tables, which can contain views, indexes, data types, operators and functions.

info
#Keyword/ConceptDescription
1SELECTRetrieves data from one or more tables in a database.
2FROMSpecifies the table or tables to retrieve data from.
3WHEREFilters rows based on specific conditions.
4JOINCombines rows from two or more tables based on a related column.
5GROUP BYGroups rows that have the same values into summary rows.
6ORDER BYSorts the result-set by one or more columns.
7HAVINGFilters data after grouping using GROUP BY.
8INSERTAdds new records to a table.
9UPDATEModifies existing records in a table.
10DELETERemoves records from a table.
11CREATECreates a new database object (table, view, etc.).
12ALTERModifies an existing database object.
13DROPDeletes a database object.
14Aggregation Functions (MIN, MAX, AVG, COUNT)Performs calculations on a set of values and returns a single value.
15Joins (INNER, LEFT, FULL)Retrieves data from multiple tables with matching or non-matching values.
16CASE StatementAdds conditional logic within SQL queries.
17Window Functions (RANK, DENSE_RANK, ROW_NUMBER)Performs calculations across a set of table rows related to the current row.
  1. Structure and Content: In SQL, the structure refers to how data is organized in tables, and the content refers to the actual data stored within those tables.
CategoryAliasDescription
TupleRowRecord
AttributeColField

For example, the following SQL code creates a table named students

-- Create a table
CREATE TABLE Students (
ID INT,
Name VARCHAR(50),
Age INT
);

-- Insert a record
INSERT INTO Students VALUES (1, 'Alice', 22);

-- Query the table
SELECT * FROM Students;

-- Update a record
UPDATE Students SET Age = 23 WHERE ID = 1;

-- Delete a record
DELETE FROM Students WHERE ID = 1;
  1. Advantages: Platform Independent? yes and no โ€” it depends. The core SQL language (based on ANSI/ISO standards) is platform-independent, meaning the basic syntax and conceptsโ€”like SELECT, INSERT, UPDATE, and DELETE are the same across different database systems. โŒ But, SQL Implementations Are Not Fully Platform Independent:

Different Database Management Systems (DBMS)โ€”like MySQL, PostgreSQL, Oracle, SQL Server, and SQLiteโ€”extend SQL differently. They may:

  • Use different data types (VARCHAR vs TEXT, etc.)
  • Have custom functions and features
  • Handle stored procedures, triggers, and syntax differently
  • Offer different tools and performance optimizations
  • So, SQL code written for one system may not work exactly the same on another without adjustments.

๐Ÿ—ƒ๏ธ Why Learn SQL?

SQL (Structured Query Language) is the standard language used to manage and query relational databases โ€” the most common way data is stored across businesses. Whether it's MySQL, PostgreSQL, SQL Server, or SQLite โ€” they all speak SQL! ๐Ÿ’ฌ

Data engineering is the process of collecting, transforming, and storing data in a way that allows for easy analysis and access. SQL is a critical tool in this process because it allows data engineers to:

  1. โœ…Retrieve data: SQL enables data engineers to retrieve specific data from a database by querying it based on certain criteria. This helps to ensure that data is accessible and easy to find.
  2. โœ…Manipulate data: SQL also enables data engineers to manipulate data within a database by adding, deleting, or updating data. This helps to ensure that data is accurate and up-to-date.
  3. โœ…Manage data: SQL enables data engineers to manage databases by creating tables, defining relationships between tables, and setting up security permissions. This helps to ensure that data is organized and secure.

๐Ÿ“Š SQL: A Must-Have for Data-Driven Rolesโ€‹

SQL is a critical skill for anyone working with data. It empowers you to extract, analyze, and transform information efficiently.

Here are some roles where SQL is a game-changer:

๐Ÿ‘จโ€๐Ÿ’ป Data Analysts
๐Ÿ› ๏ธ Data Engineers
๐Ÿ”ฌ Data Scientists
๐Ÿ“ˆ Business Intelligence Professionals
๐Ÿ’ป Software Developers
๐Ÿ“ฃ Marketers
๐Ÿ“ฆ Product Managers
๐Ÿ“Š Business Analysts

From running ad-hoc queries to building pipelines and dashboards โ€” SQL is everywhere in data work! ๐Ÿš€


Getting started with SQLโ€‹

1. Set up your development environment: Go to MySQL Downloads Page:

  • Visit MySQL Workbench Downloads.

2. Download the Installer:: To write your first SQL commands, follow these steps:

Conclusionโ€‹

Learning SQL empowers you to talk to data, unlock insights and build data-driven solutionsโ€”making it one of the most valuable and versatile skills in the digital world.