Introduction to SQL — The Language of Data

SQL (Structured Query Language) is the standard language used to interact with relational databases — systems that organize data into structured tables. It allows data professionals to create, modify, and retrieve information efficiently, making it a cornerstone skill for anyone working in data analysis, engineering, or data science. From small business dashboards to massive enterprise systems, SQL is everywhere: it powers financial transactions, manages customer data, and supports analytics pipelines. Its importance lies in its universality — regardless of the database technology you use (MySQL, PostgreSQL, SQLite, or SQL Server), SQL remains the key to accessing, managing, and understanding data.

Now let’s look at some of the most common SQL commands and what they do:

· SELECT — Retrieves data from a table.

SELECT name, age FROM customers

This command fetches the specified columns (in this case, name and age) from the customers table.

· CREATE TABLE — Creates a new table structure.

CREATE TABLE customers (

    customer_id INT PRIMARY KEY,

    name VARCHAR(50),

    city VARCHAR(50)

);

This command defines a table named customers with three columns, including a primary key that uniquely identifies each record.

· WHERE — Filters records based on a condition.

SELECT * FROM customers WHERE city = ‘Vienna’;

It limits results to rows that meet the condition — in this example, customers who live in Vienna.

· DISTINCT — Returns only unique values, removing duplicates.

SELECT DISTINCT city FROM customers;

Useful when you want to see all unique cities in your dataset.

· FILTERS with OR, AND, NOT, BETWEEN — Combine conditions for more precise results.

SELECT * FROM orders

WHERE (price BETWEEN 50 AND 200) AND NOT (status = ‘Cancelled’);

This retrieves all orders priced between 50 and 200, excluding those marked as cancelled.

· ORDER BY — Sorts query results in ascending or descending order.

SELECT * FROM customers ORDER BY name ASC;

Adding DESC instead of ASC sorts results in reverse order.

· DROP — Deletes an entire table or database structure.

DROP TABLE customers;

Use this carefully — it permanently removes the table and all its data.

· DELETE — Removes specific rows from a table without deleting the structure.

DELETE FROM customers WHERE city = ‘Paris’;

Deletes only the records that match the condition, keeping the table intact.

· INSERT INTO — adds new rows to a table.

INSERT INTO customers (customer_id, name, city)

VALUES (4, ‘Anna’, ‘Graz’);

Lets you add data directly into your tables — essential for small manual updates or testing

· ALTER TABLE — modifies an existing table (add, remove, or rename columns).

ALTER TABLE customers ADD COLUMN email VARCHAR(100);

Perfect when your data model evolves and you need to store new attributes.

· TRUNCATE TABLE — deletes all rows but keeps the table structure intact.

TRUNCATE TABLE orders;

Faster than DELETE when you want to clear a table completely but plan to reuse it.

These commands form the foundation of SQL — the essential toolkit for anyone who wants to query, clean, and manage data. Once you master them, you can begin combining operations, joining tables, and creating complex analytical queries that turn raw data into valuable insights.


Discover more from The Data Viewfinder

Subscribe to get the latest posts sent to your email.

Leave a comment